建立使用pytables一个巨大的numpy的阵列 [英] Building a huge numpy array using pytables

查看:2245
本文介绍了建立使用pytables一个巨大的numpy的阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能创建一个使用pytables一个巨大的numpy的数组。我试过,但给了我ValueError错误:数组是太大了。错误:

 导入numpy的是NP
导入表结核病
NDIM = 60000
h5file = tb.openFile('test.h5',模式='W',标题=测试阵列)
根= h5file.root
h5file.createArray(根,测试,np.zeros((NDIM,NDIM),DTYPE =浮动))
h5file.close()


解决方案

您可以尝试使用tables.CArray类,因为它支持COM pression但是......

我认为问题更多的是比numpy的,因为pytables您正在创建使用numpy的与pytables存放前阵。

在这种方式,你需要大量的内存来执行 np.zeros((NDIM,NDIM) - 这很可能是异常的地方的地方:是:ValueError错误数组是太大了。提高。

如果矩阵/数组不密集,那么你可以使用稀疏矩阵重$ P $可用psentation在SciPy的:<一href=\"http://docs.scipy.org/doc/scipy/reference/sparse.html\">http://docs.scipy.org/doc/scipy/reference/sparse.html

另一个解决方案是通过尝试,如果你不需要整个数组一次块访问阵列 - 看看这个线程:的 Python的numpy的非常大的矩阵

How can I create a huge numpy array using pytables. I tried this but gives me the "ValueError: array is too big." error:

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()

解决方案

You could try to use tables.CArray class as it supports compression but...

I think questions is more about numpy than pytables because you are creating array using numpy before storing it with pytables.

In that way you need a lot of ram to execute np.zeros((ndim,ndim) - and this is probably the place where exception: "ValueError: array is too big." is raised.

If matrix/array is not dense then you could use sparse matrix representation available in scipy: http://docs.scipy.org/doc/scipy/reference/sparse.html

Another solution is to try to access your array via chunks if it you don't need whole array at once - check out this thread: Python Numpy Very Large Matrices

这篇关于建立使用pytables一个巨大的numpy的阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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