将大型稀疏矩阵转换为COO时出错(Error converting large sparse matrix to COO)
我遇到了下面的问题,试图浏览两个大的CSR矩阵:
/usr/lib/python2.7/dist-packages/scipy/sparse/coo.pyc in _check(self)
229 raise ValueError('negative row index found')
230 if self.col.min() < 0:
--> 231 raise ValueError('negative column index found')
232
233 def transpose(self, copy=False):
ValueError: negative column index found
我可以非常简单地通过尝试将大型矩阵转换为合并矩阵来重现此错误。 以下代码对于N = 10 ** 9起作用,但对于N = 10 ** 10起作用。
from scipy import sparse
from numpy import random
N=10**10
x = sparse.lil_matrix( (1,N) )
for _ in xrange(1000):
x[0,random.randint(0,N-1)]=random.randint(1,100)
y = sparse.coo_matrix(x)
对于coo矩阵有没有大小限制? 有没有解决的办法?
I ran into the following issue trying to vstack two large CSR matrices:
/usr/lib/python2.7/dist-packages/scipy/sparse/coo.pyc in _check(self)
229 raise ValueError('negative row index found')
230 if self.col.min() < 0:
--> 231 raise ValueError('negative column index found')
232
233 def transpose(self, copy=False):
ValueError: negative column index found
I can reproduce this error very simply by trying to convert a large lil matrix to a coo matrix. The following code works for N=10**9 but fails for N=10**10.
from scipy import sparse
from numpy i