gpt4 book ai didi

python - 尝试在 h5py : ValueError: Unable to set extend dataset (Dimension cannot exceed the existing maximal size 中扩展现有数据集时出错

转载 作者:行者123 更新时间:2023-12-05 06:38:58 26 4
gpt4 key购买 nike

我正在尝试在 h5py 中创建一个可调整大小的数据集。它应该是一个简单的一维数组,其中写入了一些初始值,然后在可用时用其他值进行更新。当我尝试这个时:

ds = g2.create_dataset(wf, maxshape=(None), chunks=True, data=values)
size = ds.shape[0] + len(values)
ds.resize(size, axis=0)

我收到这个错误:

ValueError: Unable to set extend dataset (Dimension cannot exceed the existing maximal size (new: 120 max: 60))

但是,似乎提供数据或设置形状会覆盖 maxshape,并且数据集不会调整大小,并显示当前最大形状是最初提供的数据或在 shape 属性中设置的数据的消息。

根据h5py documentation这正是应该如何完成的,将 maxshape 设置为 None 应该提供无限扩展,而将 block 设置为 True 应该启用自动 block 大小确定。

我也试过这样的,分别添加数据:

ds = g2.create_dataset(wf,(100,), maxshape=(None), chunks=True, dtype='i')

它会抛出同样的错误,现在我不确定我是否错误地设置了维度,或者它是否与数据类型或形状有关。

最佳答案

我唯一不同的是使用 (None,) 作为形状,而不是 (None);那就是确保我给它一个元组形状。没有逗号我没试过。

In [177]: f=h5py.File('test1.h5','w')
In [178]: ds = f.create_dataset('name', maxshape=(None,), chunks=True, data=np.arange(10))
In [179]: ds.shape
Out[179]: (10,)
In [180]: ds.resize((20,))
In [181]: ds[:]
Out[181]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
In [182]: ds[10:]=np.arange(10,20)
In [183]: ds[:]
Out[183]:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19])

maxshape 必须是元组。 resize 不适用于 (None)

关于python - 尝试在 h5py : ValueError: Unable to set extend dataset (Dimension cannot exceed the existing maximal size 中扩展现有数据集时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45311835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com