[Numpy-discussion] unpacking bytes directly in numpy
Thomas Robitaille
thomas.robitaille at gmail.com
Sat Sep 26 09:33:28 EDT 2009
Hi,
To convert some bytes to e.g. a 32-bit int, I can do
bytes = f.read(4)
i = struct.unpack('>i', bytes)[0]
and the convert it to np.int32 with
i = np.int32(i)
However, is there a more direct way of directly transforming bytes
into a np.int32 type without the intermediate 'struct.unpack' step?
Thanks for any help,
Tom
More information about the NumPy-Discussion
mailing list