gpt4 book ai didi

python - 使用 pytables 构建一个巨大的 numpy 数组

转载 作者:太空狗 更新时间:2023-10-29 21:15:11 25 4
gpt4 key购买 nike

如何使用 pytables 创建一个巨大的 numpy 数组。我试过了,但给了我“ValueError:数组太大。”错误:

import numpy as np
import tables as tb
ndim = 60000
h5file = tb.openFile('test.h5', mode='w', title="Test Array")
root = h5file.root
h5file.createArray(root, "test", np.zeros((ndim,ndim), dtype=float))
h5file.close()

最佳答案

顺应@b1r3k 的响应,要创建一个您不会一次访问所有内容的数组(即,将整个内容放入内存),您需要使用 CArray(分 block 数组).这个想法是,您随后将逐步填充和访问它:

import numpy as np
import tables as tb
ndim = 60000
h5file = tb.openFile('test.h5', mode='w', title="Test Array")
root = h5file.root
x = h5file.createCArray(root,'x',tb.Float64Atom(),shape=(ndim,ndim))
x[:100,:100] = np.random.random(size=(100,100)) # Now put in some data
h5file.close()

关于python - 使用 pytables 构建一个巨大的 numpy 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8642626/

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