我想从一个二进制数据文件中读取, 在我的脚本的旧 matlab 版本中,这是由
file=fread(data,'bit16');
在 python 中哪个是等价的东西? 我试过了
with open file(data, "rb") as f:
d = np.fromfile(f, "<i2", count = 10000)
自 the matlab documentation表示 bitn 是 n 位的有符号整数类型
我尝试了不同的数据类型 ( "<>i2", "int16")
不幸的是,这并没有给我正确的数据。
最佳答案
您可以尝试使用与处理 half precision floting point 的 numpy.frombuffer
关联的 float16
数据类型。 (bit16
在 matlab 中)。类型文件是 here .
关于python - 在python中打开二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18186458/