how to export HDF5 file to NumPy using H5PY?

l.z.lz picture l.z.lz · Apr 23, 2012 · Viewed 20.4k times · Source

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

Answer

Danica picture Danica · Apr 23, 2012

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