python如何查看hdf5文件

704次阅读
没有评论

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')
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-07-17发表,共计738字。
新手QQ群:570568346,欢迎进群讨论 Python51学习