h5py返回索引中意外的结果 [英] h5py returning unexpected results in indexing

查看:232
本文介绍了h5py返回索引中意外的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图填补h5py数据集的一系列,我按顺序产生numpy的阵列,所以我的记忆可以处理它。

I'm attempting to fill an h5py dataset with a series of numpy arrays that I generate in sequence so my memory can handle it.

的h5py阵列被初始化,使得第一尺寸可具有任何大小,

The h5py array is initialised so that the first dimension can have any magnitude,

f.create_dataset('x-data', (1, maxlen, 50), maxshape=(None, maxlen, 50))

生成每个numpy的阵列型X之后,我使用

After generating each numpy array X, I am using

f['x-data'][alen:alen + len(data),:,:] = X

其中,例如,在第一阵列中,阿伦= 0和len(数据)= 10056。然后我增加ALEN所以接下来的阵列将在最后一个结束的地方开始。

Where for example, in the first array, alen=0 and len(data)=10056. I then increment alen so the next array will start from where the last one ended.

print f['x-data'][alen:alen + len(data),:,:].shape, alen, len(data)

(1L, 60L, 50L) 0 10056

有谁知道为什么?0:10056索引是作为跨preTED为1L

Does anyone know why the 0:10056 indexing is being interpreted as 1L?

推荐答案

我发现从乐于助人的人的用户组答案。

I found the answer from a helpful person on the user group.

该maxshape(无)功能并不意味着数据集自动调整 - 必须每次添加新的输入时间调整。所以,第一个维度之前必须添加新的数据来增加:

The maxshape(None) feature does not mean that the dataset automatically resizes - it must be resized each time new input is added. So the first dimension must be increased before adding new data:

    x.resize((x.shape[0] + X.shape[0], X.shape[1], X.shape[2]))
    y.resize((y.shape[0] + Y.shape[0], Y.shape[1], Y.shape[2]))

该数据集,然后添加正确的价值观。

The dataset then adds the values correctly.

这篇关于h5py返回索引中意外的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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