Reading binary big endian files in python

て烟熏妆下的殇ゞ 提交于 2020-08-07 18:14:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!