将hdf5文件(.h5、.hdf5)转为txt文件

1.用软件HDF_Explorer查看hdf5的文件存储层次。
软件链接:https://pan.baidu.com/s/1vTazr7DemyNGRYI__N4K9g
提取码:z7rj
下载->解压缩->运行HdfExp.exe->hdf5文件拖入->可以看.h5文件的结构了,根据结构去转化

注意:这个例子possion_4096数据是三维的:[4000,4096,6]
在这里插入图片描述

例子:因为数据是三维的,所以会有循环读取,针对不同的数据要对应处理

import h5py
import numpy as np
import os
h5_filename='Patches_noHole_and_collected.h5'
out_path="data/"
f = h5py.File(h5_filename)
input = f['poisson_4096'][:]
print(input.shape)
#创建input项的文件夹
input_dir_path=out_path+'input/'
if os.path.exists(input_dir_path)==False:
    os.makedirs(input_dir_path)
input_file_path=input_dir_path+'input'
for i in range(len(input)):#因为数据是三维的,所以循环读取
    temp_path=input_file_path+str(i)+'.txt'
    np.savetxt(temp_path,input[i])
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值