本文小编为大家详细介绍“python中怎么查看hdf5文件”,内容详细,步骤清晰,细节处理妥当,希望这篇“python中怎么查看hdf5文件”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
说明
1、hdf5不支持用其他浏览器打开,建议写一个代码来进行读取。
2、读取HDF5文件中的所有数据集,然后传输到路径。
实例
# 读取HDF5文件中的所有数据集
def traverse_datasets(hdf_file):
import h5py
def h5py_dataset_iterator(g, prefix=''):
for key in g.keys():
item = g[key]
path = '{}/{}'.format(prefix, key)
if isinstance(item, h5py.Dataset): # test for dataset
yield (path, item)
elif isinstance(item, h5py.Group): # test for group (go down)
yield from h5py_dataset_iterator(item, path)
with h5py.File(hdf_file, 'r') as f:
for (path, dset) in h5py_dataset_iterator(f):
print(path, dset)
return None
# 传入路径即可
traverse_datasets('datasets/train_catvnoncat.h5')
读到这里,这篇“python中怎么查看hdf5文件”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注天达云行业资讯频道。