如何在python中知道HDF5数据集名称 [英] How to know HDF5 dataset name in python

查看:357
本文介绍了如何在python中知道HDF5数据集名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将HDF5文件读入Python并进行一些编码工作. 要在python环境中访问HDF5文件中的数据,您需要HDF5文件的数据集名称.但是,我不知道如何找到数据集名称,我想寻求帮助.

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]

推荐答案

file是python字典.因此,您可以遍历file并存储所有数据集,例如:

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)
...     ...

如果仅用于列表: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']

这篇关于如何在python中知道HDF5数据集名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆