问题
I'd like to use python read a large binary file in ieee big endian 64bit floating point format, but am having trouble getting the correct values. I have a working method in matlab, as below:
fid=fopen(filename,'r','ieee-be');
data=fread(fid,inf,'float64',0,'ieee-be');
fclose(fid)
I've tried the following in python:
data = np.fromfile(filename, dtype='>f', count=-1)
This method doesn't throw any errors, but the values it reads are extremely large and incorrect. Can anyone help with a way to read these files? Thanks in advance.
回答1:
Using >f
will give you a single-precision (32-bit) floating point value. Instead, try
data = np.fromfile(filename, dtype='>f8', count=-1)
来源:https://stackoverflow.com/questions/51371123/reading-binary-big-endian-files-in-python