更新h5py数据集 [英] Updating h5py Datasets

查看:405
本文介绍了更新h5py数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人有从h5py更新hdf5数据集的想法吗? 假设我们创建一个像这样的数据集:

Does any one have an idea for updating hdf5 datasets from h5py? 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")

是否可以将dset扩展为3x3的numpy数组?

Is it possible to extend the dset to a 3x3 numpy array?

推荐答案

您需要使用"extendable"属性创建数据集.初始创建数据集后,无法更改此设置.为此,您需要使用"maxshape"关键字. maxshape元组中的None值表示该尺寸可以无限制.因此,如果f是HDF5文件:

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. A value of None in the maxshape tuple means that that dimension can be of unlimited size. So, if f is an HDF5 file:

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

创建一个大小为(2,2)的数据集,该数据集可以沿第一个维度无限扩展,而沿第二个维度可以无限扩展至3.现在,您可以使用resize扩展数据集:

creates a dataset of size (2,2), which may be extended indefinitely along the first dimension and to 3 along the second. Now, you can extend the dataset with resize:

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

第一维可以任意增加:

dset.resize((10,3))

这篇关于更新h5py数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆