Python3.6 读写HDF5

本文详细介绍了如何使用Python的h5py库进行HDF5文件的读取与写入操作,包括创建数据集、读取数据集内容及结构等关键步骤。
# -*- coding: utf-8 -*-
import h5py
import numpy as np

f = h5py.File('xx.h5','r')
for key in f.keys():
    print(f[key].name)
    print(f[key].shape)
    print(f[key].value)

print(f.keys())



#other ways
#读HDF 5
import h5py
filename = 'file.hdf5'
f = h5py.File(filename, 'r')

# List all groups
print("Keys: %s" % f.keys())
a_group_key = list(f.keys())[0]

# Get the data
data = list(f[a_group_key])


#写HDF 5
#!/usr/bin/env python
import h5py

# Create random data
import numpy as np
data_matrix = np.random.uniform(-1, 1, size=(10, 3))

# Write data to HDF5
data_file = h5py.File('file.hdf5', 'w')
data_file.create_dataset('group_name', data=data_matrix)
data_file.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值