How do I traverse a hdf5 file using h5py

后端 未结 3 570
不思量自难忘°
不思量自难忘° 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:38

    Well this is kind of an old thread but I thought I'd contribute anyway. This is what I did in a similar situation. For a data structure set up like this:

    [group1]
        [group2]
            dataset1
            dataset2
        [group3]
            dataset3
            dataset4
    

    I used:

    datalist = []
    def returnname(name):
        if 'dataset' in name and name not in datalist:
            return name
        else:
            return None
    looper = 1
    while looper == 1:
        name = f[group1].visit(returnname)
        if name == None:
            looper = 0
            continue
        datalist.append(name)
    

    I haven't found an h5py equivalent for os.walk.

提交回复
热议问题