如何使用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)
有关更多信息,请参阅文档.
您需要更改这一行:
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
| 归档时间: |
|
| 查看次数: |
7833 次 |
| 最近记录: |