在python中读取二进制大字节序文件 [英] Reading binary big endian files in python
本文介绍了在python中读取二进制大字节序文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用python读取ieee big endian 64位浮点格式的大型二进制文件,但是在获取正确的值时遇到了麻烦.我在matlab中有一种工作方法,如下所示:
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)
我在python中尝试了以下方法:
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.
推荐答案
使用>f
将为您提供单精度(32位)浮点值.相反,尝试
Using >f
will give you a single-precision (32-bit) floating point value. Instead, try
data = np.fromfile(filename, dtype='>f8', count=-1)
这篇关于在python中读取二进制大字节序文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文