How to dereference HDF5 links in Python?

Sometimes I get the following arrays from an HDF5 file:

val1 = {ndarray} [<HDF5 object reference> <HDF5 object reference> <HDF5 object reference>]

If I try to dereference it with an HDF5 file

f[val[0]]

I get an error

Argument 'ref' has incorrect type (expected h5py.h5r.Reference, got numpy.object_)
+4
source share
1 answer

I came across this question, trying to answer what turned out to be basically the same question in a different form. A dataset containing references to other objects is a bit uncomfortable in HDF5, but you can actually read them in a fairly simple way. The idea is to get the name of the referenced object, and then just read that object directly from the file.

HDF5, ref , file, , :

>>> name = h5py.h5r.get_name(ref, file.id)

, :

>>> data = file[name].value # ndarray with the data in it.

, , map .

0

Source: https://habr.com/ru/post/1629431/


All Articles