如何调整的HDF5数组`h5py`

问题描述 投票:8回答:2

我如何可以调整使用h5py Python库的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'
python hdf5 h5py
2个回答
9
投票

正如奥伦提到的,你需要,如果你想以后更改数组的大小创建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'

docs更多。


3
投票

你需要改变这一行:

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

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

d.resize((?, ?))

更改?到任何大小,你有什么(你也可以将其设置为无)

在这里阅读:http://docs.h5py.org/en/latest/high/dataset.html#resizable-datasets

© www.soinside.com 2019 - 2024. All rights reserved.