读取 python 中的二进制大端文件
Reading binary big endian files in python
我想使用 python 读取 ieee big endian 64 位浮点格式的大型二进制文件,但无法获取正确的值。我在matlab中有一个工作方法,如下:
fid=fopen(filename,'r','ieee-be');
data=fread(fid,inf,'float64',0,'ieee-be');
fclose(fid)
我在 python 中尝试了以下方法:
data = np.fromfile(filename, dtype='>f', count=-1)
此方法不会抛出任何错误,但它读取的值非常大且不正确。任何人都可以帮助阅读这些文件吗?提前致谢。
使用>f
将为您提供单精度(32 位)浮点值。相反,尝试
data = np.fromfile(filename, dtype='>f8', count=-1)
我想使用 python 读取 ieee big endian 64 位浮点格式的大型二进制文件,但无法获取正确的值。我在matlab中有一个工作方法,如下:
fid=fopen(filename,'r','ieee-be');
data=fread(fid,inf,'float64',0,'ieee-be');
fclose(fid)
我在 python 中尝试了以下方法:
data = np.fromfile(filename, dtype='>f', count=-1)
此方法不会抛出任何错误,但它读取的值非常大且不正确。任何人都可以帮助阅读这些文件吗?提前致谢。
使用>f
将为您提供单精度(32 位)浮点值。相反,尝试
data = np.fromfile(filename, dtype='>f8', count=-1)