2012-03-12 182 views
3

我试图使用大10^5×10^5个稀疏矩阵,但似乎对SciPy的是运行起来:SciPy的大型稀疏矩阵

n = 10 ** 5 
x = scipy.sparse.rand(n, n, .001) 

得到

ValueError: Trying to generate a random sparse matrix such as the 
    product of dimensions is greater than 2147483647 - this is not 
    supported on this machine 

有谁知道为什么限制在那里,如果我能避免它? (fyi,我正在使用4GB内存的macbook air和enthought分配)

回答

10

这是一个限制,从scipy.sparse.rand()的实现方式产生。您可以推出自己的随机矩阵世代以规避此限制:

n = 10 ** 5 
density = 1e-3 
ij = numpy.random.randint(n, size=(2, n * n * density)) 
data = numpy.random.rand(n * n * density) 
matrix = scipy.sparse.coo.coo_matrix((data, ij), (n, n))