[Python] Read multiple datasets from same Group in h5 file using h5py

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I have several groups in my h5 file: 'group1', 'group2', ... and each group has 3 different datasets: 'dataset1', 'dataset2', 'dataset3', all of which are arrays with numerical values but the size of array is different.

    My goal is to save each dataset from group to a numpy array.

    Example:

    import h5py
    filename = '../Results/someFileName.h5'
    data = h5py.File(filename, 'r')


    Now I can easily iterate over all groups with

    for i in range(len(data.keys())):
    group = list(data.keys())


    but I can't figure out how to access the datasets within the group. So I am looking for something like MATLAB:

    hinfo = h5info(filename);
    for i = 1:length(hinfo.Groups())
    datasetname = [hinfo.Groups(i).Name '/dataset1'];
    dset = h5read(fn, datasetname);


    Where dset is now an array of numbers.

    Is there a way I could do the same with h5py?

    Continue reading...

Compartilhe esta Página