如何用`h5py`调整HDF5数组的大小

MRo*_*lin 10 python hdf5 h5py

如何使用h5pyPython库调整HDF5阵列的大小?

我已经尝试使用该.resize方法并在chunks设置为的数组上True.唉,我还在遗漏一些东西.

In [1]: import h5py

In [2]: f = h5py.File('foo.hdf5', 'w')

In [3]: d = f.create_dataset('data', (3, 3), dtype='i8', chunks=True)

In [4]: d.resize((6, 3))
/home/mrocklin/Software/anaconda/lib/python2.7/site-packages/h5py/_hl/dataset.pyc in resize(self, size, axis)
--> 277         self.id.set_extent(size)
ValueError: unable to set extend dataset (Dataset: Unable to initialize object)

In [11]: h5py.__version__ 
Out[11]: '2.2.1'
Run Code Online (Sandbox Code Playgroud)

小智 10

正如Oren所提到的,如果您想稍后更改数组大小maxshape,dataset则需要在创建时使用.设置尺寸以None允许您稍后将该尺寸调整为2**64(h5的限制):

In [1]: import h5py

In [2]: f = h5py.File('foo.hdf5', 'w')

In [3]: d = f.create_dataset('data', (3, 3), maxshape=(None, 3), dtype='i8', chunks=True)

In [4]: d.resize((6, 3))

In [5]: h5py.__version__
Out[5]: '2.2.1'
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅文档.


Ore*_*ren 4

您需要更改这一行:

d = f.create_dataset('data', (3, 3), dtype='i8', chunks=True)
Run Code Online (Sandbox Code Playgroud)

d = f.create_dataset('data', (3, 3), maxshape=(?, ?), dtype='i8', chunks=True) 

d.resize((?, ?))
Run Code Online (Sandbox Code Playgroud)

改变任意大小(您也可以将其设置为None

阅读此处: http ://docs.h5py.org/en/latest/high/dataset.html#ressized-datasets