二进制文件转npy文件(Python3)

June 17, 2019, 7:36 p.m.

read: 1408

以下demo只支持float格式,仅提供思路,其他数据类型需自行扩展:

import numpy as np
import struct
def bin2npy(bin_file_path, npy_file_path, type='float'):
    assert type in ['float']
    out_data = []
    with open(bin_file_path, mode='rb') as bin_file:
        in_data = bin_file.read()
        for i in range(len(in_data)//4):
            out_data.append(struct.unpack("f", in_data[i*4:(i+1)*4]))
    # return np.array(out_data)
    np.save(npy_file_path, np.array(out_data))
if __name__ == '__main__':
    bin2npy('/Users/hupeng/work/60/lstm_in_63.bin', '/Users/hupeng/work/60/lstm_in_63.npy')




PyTorch tensor 翻转

转自https://discuss.pytorch.org/t/how-to-reverse-a-torch-tensor/382 形状为(10)的tensor翻转 tensor = torch.r…

Android 动态权限

文章标题:Android 动态权限文章内容:1. 添加权限到 AndroidManifest.xml2. 添加以下语句到build.gradle=>dependenciesimplementa…

此站点由 ASP.NETIIS 驱动 | © 2018-2023 hupeng.me. All Rights Reserved.