Вопрос

I am saving some data to HDF5 file via h5py. They are mixed-types data, some are proper numpy arrays, many are scalars or strings. Scalars and strings get "encoded" to numpy arrays by h5py automatically (that is very nice), but I would like to do the reverse now: when reading those data, get it converted to native python type, instead of seeing scalars as 0d shapes, strings as <HDF5 dataset "plots": shape (), type "|S207"> and such.

Is there an easy way to achieve that, without me having to check for array dtype manually?

It is fine that an extra object will be created for every conversion.

Это было полезно?

Решение

Not sure if it would make sense for your use-case, but you might think about storing single scalars or strings as attributes:

http://www.h5py.org/docs/intro/quick.html#attributes

Другие советы

Would it make sense for you to use h5pom? This might be overkill for you, but it should do what you describe, although you'd probably have to work with the whole ORM more than you'd wish (Caveat:I've played around with it but never used it in anger).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top