No way to read numpy arrays from h5 files created using HDF5File

Issue #503 wontfix
Quentin Parsons created an issue

Functionality exists (by which I mean dolfin methods) to save numpy arrays into .h5 files using something like:

import numpy as np
from dolfin import *

filename = "my_excellent_file.h5"
my_numpy_array = np.array([0.1, 0.2, 0.3])
f = HDF5File(mpi_comm_world(), filename, 'w')
f.write(my_numpy_array, '/my_data')  # note that the '/' appears to be required here...

...but there is currently no (dolfin) method corresponding to a 'read' to pull this array back out of the file for subsequent processing.

There is a workaround however. Something like the following can be used:

import h5py

my_readback_array = np.array([])    
with h5py.File(filename, 'r') as f:
    my_readback_array = f['my_data'][()]  # no '/' this time...

Comments (4)

  1. Log in to comment