I have some C++ that reads an attribute from a dataset like this:
hsize_t szN[1] = {3};
hid_t long3_id = H5Tarray_create(H5T_NATIVE_LONG, 1, szN);
long val[3];
auto const attrH = H5Aopen_by_name(handle_, dset.c_str(), attr.c_str(), H5P_DEFAULT, H5P_DEFAULT);
H5Aread(attrH, long3_id, val);
I want to write this attribute using h5py
, but I cannot figure out how. If I simply do:
dset.attrs['attribute'] = [3, 3, 3]
for example, then the attribute is created as integers with a dataspace of [3]. I think I need it to be an array datatype with dataspace [1]. I have also tried:
traj.attrs.create('attribute', [3, 3, 3], dtype=h5py.h5t.array_create(h5py.h5t.NATIVE_INT64, (3,)))
but this results in:
ValueError: Changing the dtype to a subarray type is only supported if the total itemsize is unchanged
I can’t find any examples using h5t.array_create()
. Any pointers much appreciated!