l.z.lz l.z.lz - 9 months ago 64
Python Question

how to export HDF5 file to NumPy using H5PY?

I have an existing hdf5 file with three arrays, i want to extract one of the arrays using h5py.

Answer Source

h5py already reads files in as numpy arrays, so just:

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