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]

更多推荐

bin文件python读取