Revision 746f66b8cfde9400ce3f4021a3283f10e2caa70f authored by Ilan Schnell on 21 January 2021, 00:52:57 UTC, committed by Ilan Schnell on 21 January 2021, 00:52:57 UTC
1 parent 173c848
Raw File
ndarray.py
#
# This example illusatrates how binary data can be efficiently be passed
# between a bitarray object and an ndarray with dtype bool
#
from __future__ import print_function

import bitarray
import numpy

a = bitarray.bitarray('100011001001')
print(a)

# bitarray  ->  ndarray
b = numpy.frombuffer(a.unpack(), dtype=bool)
print(repr(b))

# ndarray  ->  bitarray
c = bitarray.bitarray()
c.pack(b.tostring())

assert a == c
back to top