我如何可以调整使用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'
正如奥伦提到的,你需要,如果你想以后更改数组的大小创建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更多。
你需要改变这一行:
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