I have a sparse matrix random matrix created as follows:
import numpy as np from scipy.sparse import rand foo = rand(100, 100, density=0.1, format='csr')
I want to iterate over cells in a specific row and do two calculations:
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 """
source share