Skip to content Skip to sidebar Skip to footer

Adding New Data Into Hdf5 File Results An Empty Array

While playing with HDF5 package for Python I discovered a strange behavior. I want to insert more data into table. But somehow I cannot get it work properly. As you can see from th

Solution 1:

You are getting fromRow AFTER you resize the X dataset. You need the value BEFORE your resize. See code below.

with h5py.File('data.hdf5', 'w') as hf:
    # Add data to new file
    dset = hf.create_dataset("X", data=tempArray1, compression="gzip", chunks=True, maxshape=(None,3), dtype='f4') # Size is as the size of tempArray1
    print(hf["X"].shape[0])
# new location to get fromRow:
    fromRow = hf["X"].shape[0]

    # Append data existing file
    hf["X"].resize((hf["X"].shape[0] + 10, 3)) # Size is as the size of X+ 10
    print(hf["X"].shape[0])        
    hf["X"][fromRow:] = tempArray2

Post a Comment for "Adding New Data Into Hdf5 File Results An Empty Array"