bin文件python读取
读取流程为:
bin --> open() as fid:
--> file_ = fid.read(长度)
--> tuple_data = struct.unpack("{长度}{格式化字符}", file_) # 其中Format Character可以从下图选择
--> tuple -> list -> array(float)

具体参考struct介绍网站
具体代码为:
with open(os.path.join(folder, name), "rb") as fid:
data_c = np.zeros((60, 40, 40), dtype=complex)
for jj in range(40):
for ii in range(40):
file_ = fid.read(120*4)
tuple_data = struct.unpack('320f', file_)
# ck2 = struct.unpack('320B', ck1)
tmp = np.array(list(tuple_data), dtype=np.float)
ck3 = tmp[0: 120: 2] + 1j * tmp[1: 120: 2]
data_c[:, ii, jj] = tmp[0: 120: 2] + 1j * tmp[1: 120: 2]
本文详细介绍使用Python读取BIN文件的过程,通过示例代码展示了如何利用struct模块解析二进制数据,转换为numpy数组,并处理成复数形式,适用于信号处理等应用场景。
1727

被折叠的 条评论
为什么被折叠?



