[英]How to resize an HDF5 array with `h5py`
如何使用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'
正如Oren所提到的,如果您想稍后更改数组大小,则需要在创建dataset
时使用maxshape
。 将尺寸设置为“ 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'
有关更多信息,请参阅文档 。
您需要更改此行:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.