Saving numpy arrays with HDF5

I have just switched from fenics 2017 to 2018.1 and am getting an error when I try to save an array using HDF5:

self.myfile.write(np.array([float(self.checkpointInt)]), ‘checkpointInt’)
AttributeError: ‘numpy.ndarray’ object has no attribute ‘_cpp_object’

It seems that fenics no longer supports the saving of np arrays or ints or floats in HDF5. I just need to save an int using the HDF5 format in fenics. Anyone have any ideas how to do this with the 2018 version?

Thanks,
Jared

I’m also running into this problem currently. Were you ever able to resolve this?

This probably wasn’t answered because there was no attempt at providing a MWE or context.

You could probably just use h5py.

It sounds like a library version mismatch. Perhaps your new dolfin wasn’t compiled for the numpy that you’ve got installed. Mismatches like that can happen if pip is used to install packages.

AttributeError: ‘numpy.ndarray’ object has no attribute ‘_cpp_object’

indicates attempting to pass a numpy array to a dolfin function which requires a Function or some other backend type (i.e. which has a _cpp_object). I doubt it’s a versioning issue.

The issue is we don’t know what self.myfile is. I’m assuming dolfin.HDF5File and not a h5py.File.

True. Not enough information to be certain.

1 Like