Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open binary data in python

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.

like image 574
jrsm Avatar asked Mar 31 '26 17:03

jrsm


1 Answers

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.

like image 67
marsei Avatar answered Apr 03 '26 07:04

marsei