import h5py
filename = 'file.hdf5'
with h5py.File(filename, 'r') as f:
# List all groups
print("Keys: %s" % f.keys())
a_group_key = list(f.keys())[0]
# Get the data
data = list(f[a_group_key])
写入HDF5
#!/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
with h5py.File('file.hdf5', 'w') as data_file:
data_file.create_dataset('group_name', data=data_matrix)
for key in f.keys():
print(key) #Names of the groups in HDF5 file.
提取数据
#Get the HDF5 group
group = f[key]
#Checkout what keys are inside that group.
for key in group.keys():
print(key)
data = group[some_key_inside_the_group].value
#Do whatever you want with data
#After you are done
f.close()
读取HDF5
写入HDF5
有关详细信息,请参见h5py docs。
替代品
对于您的应用程序,以下内容可能很重要:
另请参见:Comparison of data serialization formats
如果您正在寻找创建配置文件的方法,那么您可能需要阅读我的短文Configuration files in Python
你可以用熊猫。
读取文件
通过打印HDF5组来研究文件的结构
提取数据
相关问题 更多 >
编程相关推荐