3

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.

2
  • 2
    how did you write the data file? Commented Aug 12, 2013 at 12:57
  • 1
    Just for whatever it's worth, np.fromfile('test.dat', np.int16) properly recovers data written from matlab with fwrite(fid, data, 'bit16') on my system. Commented Aug 12, 2013 at 13:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.