sum1 = row1.sum()
idx1 = row1.indices
data1 = row1.data
idx2 = row2.indices
data2 = row2.data
sum2 = data1[np.in1d(idx1, idx2)].dot(data2[np.in1d(idx2, idx1)])
How to iterate over a row in a SciPy sparse matrix?