Incremental writes to hdf5 with h5py

后端 未结 2 1447
后悔当初
后悔当初 2020-12-01 04:32

I have got a question about how best to write to hdf5 files with python / h5py.

I have data like:

-----------------------------------------
| timepoi         


        
2条回答
  •  庸人自扰
    2020-12-01 05:18

    Per the FAQ, you can expand the dataset using dset.resize. For example,

    import os
    import h5py
    import numpy as np
    path = '/tmp/out.h5'
    os.remove(path)
    with h5py.File(path, "a") as f:
        dset = f.create_dataset('voltage284', (10**5,), maxshape=(None,),
                                dtype='i8', chunks=(10**4,))
        dset[:] = np.random.random(dset.shape)        
        print(dset.shape)
        # (100000,)
    
        for i in range(3):
            dset.resize(dset.shape[0]+10**4, axis=0)   
            dset[-10**4:] = np.random.random(10**4)
            print(dset.shape)
            # (110000,)
            # (120000,)
            # (130000,)
    

提交回复
热议问题