How do I traverse a hdf5 file using h5py

后端 未结 3 577
不思量自难忘°
不思量自难忘° 2021-02-05 18:50

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

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

3条回答
  •  你的背包
    2021-02-05 19:42

    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)
    

提交回复
热议问题