I would think this is a simple question but I haven't found the answer so far.
I work with fairly large (~2 GB) binary data images. I load them into python with the line
data = np.memmap(filename, dtype=np.dtype('uint16'), mode='r').byteswap()
For large files this can take several seconds. Anyway, I notice that the same line but without the byteswapping takes only an instant.
So the question is this: is there a way to specify the Byte order directly in the datatype so I don't need to do the byteswap afterwards? According to http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html,
A data type object (...) describes the following aspects of the data: (...) 3. Byte order of the data (little-endian or big-endian) (...)
How do I do this for a 16-bit unsigned integer? Things like np.dtype('>uint16')
haven't worked for me, they give me a TypeError: data type ">uint16" not understood
error.
Thank you!
specify dtype as >H
(Numeric typecodes) or >u2
(Array-protocol type strings):
np.memmap('test.bin', dtype=np.dtype('>u2'), mode='r')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With