[Numpy-discussion] read not byte aligned records
Nathaniel Smith
njs at pobox.com
Tue May 5 02:15:46 EDT 2015
On Mon, May 4, 2015 at 10:21 PM, Jerome Kieffer <Jerome.Kieffer at esrf.fr> wrote:
> Hi,
> If you want to play with 10 bits data-blocks, read 5 bytes and work with 4 entries at a time...
NumPy arrays don't have any support for sub-byte alignment. So if you
want to handle such data, you either need to write some manual
packing/unpacking code (using bitshift operators, or perhaps
np.unpackbits, or whatever), or use another library designed for doing
this. You may find Cython useful to write the core packing/unpacking,
since bit-by-bit processing in a for loop is not something that
CPython is super well suited to.
Good luck,
-n
--
Nathaniel J. Smith -- http://vorpus.org
More information about the NumPy-Discussion
mailing list