Sorry if this is a very simple question on h5py.
I read the documentation, but I did not find a similar example.
I am trying to create several hdf5 datasets in Python, but it turns out that after closing the file, the data will be overwritten.
Let's say I do the following:
import numpy as np import h5py f = h5py.File('test.hdf5', 'w') f.create_dataset('data1', data = np.ones(10)) f.close() f = h5py.File('test.hdf5', 'w') f.create_dataset('data0', data = np.zeros(10)) f.close() f = h5py.File('test.hdf5', 'r') f["data1"].value f.close()
I get
KeyError: "Unable to open object (Object 'data1' does not exist)
If I add data, this requires first opening in 'w' mode, and then adding in 'a' mode, having two different statements.
import numpy as np import h5py f = h5py.File('test.hdf5', 'w') f.create_dataset('data1', data = np.ones(10)) f.close() f = h5py.File('test.hdf5', 'a') f.create_dataset('data0', data = np.zeros(10)) f.close() f = h5py.File('test.hdf5', 'r') f["data1"].value f.close()
If I open the file in 'a' mode in both cases:
import numpy as np import h5py f = h5py.File('test.hdf5', 'a') f.create_dataset('data1', data = np.ones(10)) f.close() f = h5py.File('test.hdf5', 'a') f.create_dataset('data0', data = np.zeros(10)) f.close() f = h5py.File('test.hdf5', 'r') print(f['data1'].value) f.close()
RuntimeError: unable to create link (name already exists)
According to the documentation, the data should be stored contiguously, but I did not find how to avoid overwriting the data.
How to store data on previously closed hdf5 with just one operator?