简体   繁体   English

如何使用H5PY将HDF5文件导出到NumPy?

[英]how to export HDF5 file to NumPy using H5PY?

我有一个包含三个数组的现有hdf5文件,我想使用h5py提取其中一个数组。

h5py already reads files in as numpy arrays, so just: h5py已经以numpy数组的形式读取文件,所以只需:

with h5py.File('the_filename', 'r') as f:
    my_array = f['array_name'][()]

The [()] means to read the entire array in; [()]表示读取整个数组; if you don't do that, it doesn't read the whole data but instead gives you lazy access to sub-parts (very useful when the array is huge but you only need a small part of it). 如果你不这样做,它不会读取整个数据,而是让你懒得访问子部分(当数组很大但你只需要它的一小部分时非常有用)。

For this question it is way overkill but if you have a lot of things like this to do I use a package SpacePy that makes some of this easier. 对于这个问题,这是一种矫枉过正的做法,但是如果你有很多这样的事情要做,我会使用一个包SpacePy ,这使得一些更容易。

datamodel.fromHDF5() documentation This returns a dictionary of arrays stored in a similar way to how h5py handles data. datamodel.fromHDF5() documentation返回一个数组字典,其存储方式与h5py处理数据的方式类似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM