How to know HDF5 dataset name in python

我只是一个虾纸丫 提交于 2019-12-12 09:53:02

问题


I want to read the HDF5 file into Python and do some coding work. To access the data in HDF5 file in python environment, you need dataset name of HDF5 file. However, I do not know how to find the dataset name and I would like to ask for help.

  def select_HDF_file(self):
    filename2 = QFileDialog.getOpenFileName(self.dlg, "Select output 
    file","",'*.hdf')
    dataset_name = '**************'

    file = h5py.File(filename2 , 'r')
    dataset = file[dataset_name]

回答1:


file is a python dictionary. Thus you can iterate over file and stock all datasets for example:

>>> file = h5py.File('file.h5', 'r')
>>> dataset = []
>>> for i in file.values():
...     dataset.append(i)
...     ...

If just for the list: list(file.values()).

Finally, if you just want the name of the datasets then:

list(file.keys())
['Patch_001-inlet', 'Patch_002-outlet', 'Patch_003-wall']


来源:https://stackoverflow.com/questions/45280185/how-to-know-hdf5-dataset-name-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!