简体   繁体   English

更新 h5py 数据集

[英]Updating h5py Datasets

Does any one have an idea for updating hdf5 datasets from h5py?有没有人有从 h5py 更新 hdf5 数据集的想法? Assuming we create a dataset like:假设我们创建了一个数据集,如:

import h5py
import numpy
f = h5py.File('myfile.hdf5')
dset = f.create_dataset('mydataset', data=numpy.ones((2,2),"=i4"))
new_dset_value=numpy.zeros((3,3),"=i4")

Is it possible to extend the dset to a 3x3 numpy array?是否可以将 dset 扩展到 3x3 numpy 数组?

You need to create the dataset with the "extendable" property.您需要使用“可扩展”属性创建数据集。 It's not possible to change this after the initial creation of the dataset.在初始创建数据集后无法更改此设置。 To do this, you need to use the "maxshape" keyword .为此, 您需要使用“maxshape”关键字 A value of None in the maxshape tuple means that that dimension can be of unlimited size. maxshape元组中的None值意味着该维度可以具有无限大小。 So, if f is an HDF5 file:因此,如果f是 HDF5 文件:

dset = f.create_dataset('mydataset', (2,2), maxshape=(None,3))

creates a dataset of size (2,2), which may be extended indefinitely along the first dimension and to 3 along the second.创建一个大小为 (2,2) 的数据集,它可以沿第一个维度无限扩展,沿第二个维度扩展到 3。 Now, you can extend the dataset with resize :现在,您可以使用resize扩展数据集:

dset.resize((3,3))
dset[:,:] = np.zeros((3,3),"=i4")

The first dimension can be increased as much as you like:第一个维度可以随心所欲地增加:

dset.resize((10,3))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM