2012-03-12 224 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))