h5py增量写入

it2023-03-19  77

h5py要能增量写入,在建立模型的时候需要设定是chunked模型,而这个设定需要加上参数maxshape,在要加入增量数据时再用resize修改dataset的大小,然后把数据加在dataset的最后。代码例子如下:

path = 'increment_test.h5' os.remove(path) h5f = h5py.File(path, 'a') h5f.create_dataset('t1', data=np.ones(100, ), maxshape=(None, )) print(h5f['t1'][:]) h5f.close() incre_data = np.zeros(5, ) h5f2 = h5py.File(path, 'a') dataset1 = h5f2['t1'] dataset1.resize(dataset1.shape[0] + len(incre_data), axis=0) dataset1[-len(incre_data): ] = incre_data print(h5f2['t1'][:]) h5f2.close()

 

最新回复(0)