Skip to content

H5NpArray

In H5PY np.ndarray can be saved as soon as modified. To do that there exists a class H5NpArray. This class synchronously modifies the np.ndarray and file.

Guideline

  1. Open file in write mode.
from DH5.DH5 import DH5
sd = DH5('tmp_data/test.h5', overwrite=True, save_on_edit=False)
  1. Define new item as a h5nparray
shape = (100, 1000)
sd['test_array'] = sd.h5nparray(np.zeros(shape))

H5NpArray takes the np.array as parameter to initialize the data inside the file.

  1. Modify as normal
for i in range(100):
    sd['test_array'][i, :] = np.random.random(1000)
  1. Check that data was saved
read = DH5('tmp_data/test.h5')
read['test_array']

Implementation

  • H5NpArray has __should_not_be_converted__=True, which prevents DH5 from converting it to an array and continuous using as a class

  • as soon as you run fd[key] it will run method __init__filepath__ to provide the filepath and the key to the class H5NpArray