5

I'm trying to open a binary file in Python, for which in Matlab I'm using

data = fread(file, [rows, cols], 'float','ieee-le')

In Python I tried both

data = open(file,'rb').read() &

data = np.fromfile(file, dtype=data_type, count=count)

neither of which gave expected results (for data_type I tried all formats listed on the info page).

Just reading the data, the first 25 samples look like this:

b'\xe4\xa0B\xbc\x99\x9e\x1f\xbd\xc3\x07P>m\xe0\x96=\x0c\xf6\x8a=\x90\x86\t>)

While searching for solutions I stumbled over Python's struct package, but as I know close to nothing about data formats I was not able to use it to solve the problem. Any help would therefore be highly appreciated...

1 Answer 1

5

In numpy, ieee-le float type is '<f4', which reads "little endian floating point of 4 bytes".

Thus you can open your file using:

data = np.fromfile(filename, dtype='<f4', count=count)
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.