C语言将CSR存储模式转为coo,将大型稀疏矩阵转换为COO时出错(Error converting large sparse matrix to COO)...

在尝试将大型CSR稀疏矩阵转换为COO格式时遇到错误:'negative column index found'。该问题在N=10^10时出现,但N=10^9时正常工作。可能原因是数据溢出。解决方案可能涉及检查和处理溢出,或者考虑使用不同稀疏矩阵格式。
摘要由CSDN通过智能技术生成

将大型稀疏矩阵转换为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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值