我想从二进制数据文件中读取, 在我的脚本的旧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位
的有符号整数类型我尝试了不同的dtypes ( "<>i2", "int16")
,遗憾的是,这并没有给我提供严谨的数据。
答案 0 :(得分:1)
您可以尝试使用与float16
相关联的numpy.frombuffer
数据类型来处理half precision floting point(matlab中的bit16
)。类型doc是here。