为了账号安全,请及时绑定邮箱和手机立即绑定

.bin 文件的 Python Big-Endian 转换

.bin 文件的 Python Big-Endian 转换

犯罪嫌疑人X 2023-06-20 16:29:37
我正在尝试将 Matlab 代码转换为二进制文件的 Python。请原谅我是这门语言的新手。Matlab:fileID = fopen('file_name.bin','r');DC = fread(fileID,'single','b');Python:import numpy as npwith open('Duty_Cycle.bin','rb') as fid:    data_array = np.fromfile(fid, np.float32, dtype = '>u4')print(data_array)结果:TypeError: argument for fromfile() given by name ('dtype') and position (2)我该如何解决这个错误?
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

的签名fromfile

fromfile(file, dtype=float, count=-1, sep='', offset=0)

通过指定第二个位置参数np.float32和关键字 argument dtype='>u4',您两次给出了相同的参数,因此出现了错误。文档不是很清楚,但您可以只使用字符串规范来指定类型和字节顺序。

data_array = np.fromfile(fid, dtype='>u4')


查看完整回答
反对 回复 2023-06-20
  • 1 回答
  • 0 关注
  • 76 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信