I want to read from a binary data file, in the old matlab version of my script this is done by
file=fread(data,'bit16');
which would be the equivalent thing in python ? i tried
with open file(data, "rb") as f:
d = np.fromfile(f, "<i2", count = 10000)
since the matlab documentation says that bitn is of the type signed integer with n bits
i tried different dtypes ( "<>i2", "int16") unfortunately this doesnt give me the rigth data.
Saullo G. P. Castro
59.5k28 gold badges191 silver badges244 bronze badges
asked Aug 12, 2013 at 12:01
jrsm
1,7152 gold badges23 silver badges41 bronze badges
1 Answer 1
You may try to use float16 data type associated with numpy.frombuffer that deals with the half precision floting point (bit16 in matlab). The type doc is here.
answered Aug 12, 2013 at 14:16
marsei
7,7613 gold badges36 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
datafile?np.fromfile('test.dat', np.int16)properly recovers data written from matlab withfwrite(fid, data, 'bit16')on my system.