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...
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)