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

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

read: 97

以下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…

推荐使用 Firefox 访问此站点 | 友情链接: 张鹏的博客  Web布拉格  杨洋的博客   李号的博客   魏文成博客 | Developed by zhangpeng && hupeng | Copyright © 2018-2019 hupeng.me