[Numpy-discussion] bitwise view on numpy array
Vincent Schut
schut at sarvision.nl
Wed May 6 07:28:11 EDT 2009
Hi,
I'm gonna have large (e.g. 2400x2400) arrays of 16 and 32 bit bitfields.
I've been searching in vain for an efficient and convenient way to
represent these array's individual bit's (or, even better, configureable
bitfields of 1-4 bits each).
Of course I know I can 'split' the array in its separate bitfields using
bitwise operators and shifts, but this will greatly increase the memory
usage because it'll create one byte array for each bitfield.
So I was looking for a way to create a bitwise view on the original
array's data. I've been looking at recarray's, but the smallest element
these can use are bytes, correct?. I've been looking at ctypes arrays of
Structure subclasses, which can define bitfields. However, these will
give me an object array of elements with the Structure class subclass,
and only allow me to access the bits per array element instead of for
the entire array (or a subset), e.g. data[:].bit17-19 or someting like that.
After searching the net in vain for some hours, the list is my last
resort :-) Anyone having ideas of how to get both memory-efficient and
convenient access to single bits of a numpy array?
On a slightly related note, during my search I found some comments
saying that numpy.bool arrays use an entire byte for each element. Could
someone confirm (or, better, negate) that?
Thanks,
Vincent.
More information about the NumPy-Discussion
mailing list