本文介绍了如何使用h5py遍历hdf5文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用h5py遍历hdf5文件的所有组和数据集?

How do I traverse all the groups and datasets of an hdf5 file using h5py?

我想使用for循环或类似方法从公用根目录中检索文件的所有内容.

I want to retrieve all the contents of the file from a common root using a for loop or something similar.

推荐答案

visit()visititems()是您的朋友. cf. http://docs.h5py.org/en/latest/high /group.html#Group.visit .请注意,h5py.File也是h5py.Group.示例(未经测试):

visit() and visititems() are your friends here. Cf. http://docs.h5py.org/en/latest/high/group.html#Group.visit. Note that an h5py.File is also an h5py.Group. Example (not tested):

def visitor_func(name, node):
    if isinstance(node, h5py.Dataset):
         # node is a dataset
    else:
         # node is a group

with h5py.File('myfile.h5', 'r') as f:
    f.visititems(visitor_func)

这篇关于如何使用h5py遍历hdf5文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 14:28