python - 在python中打开二进制数据

标签 python matlab numpy

我想从一个二进制数据文件中读取, 在我的脚本的旧 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 pointnumpy.frombuffer 关联的 float16 数据类型。 (bit16 在 matlab 中)。类型文件是 here .

关于python - 在python中打开二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18186458/

相关文章:

python - 多字符串列映射和清理

Python - 数组的最大值

Matlab 绘图对数线性调频幅度

python - 使用 numpy vectorize 在二维数组中仅对一个轴进行矢量化

python - 使用 Python 和 NumPy 生成批量的 n 维 Perlin 噪声

python - 如何删除所有已定义的 SymPy 符号而不明确列出它们?

python - 将python包从本地目录导入解释器

matlab - 如何获取 numpy 数组的线性索引 (sub2ind)

matlab - MATLAB中的时间序列图

python - 值列表列表的 3D 绘图