我有一个稀疏矩阵随机矩阵,创建方法如下:
import numpy as np
from scipy.sparse import rand
foo = rand(100, 100, density=0.1, format='csr')
我想循环遍历特定行中的单元格并执行两个计算:
row1 = foo.getrow(bar1)
row2 = foo.getrow(bar2)
"""
Like the following:
sum1 = 0
sum2 = 0
for each cell x in row1:
sum1 += x
if the corresponding cell (in the same column) in row2 y is non-zero:
sum2 += x*y
"""