Sparse dot matrix products

I am trying to take the dot product of a row in a sparse matrix with transposing that row using Python. I have a huge sparse matrix X2. And I save the results (which should be a single number) in a list called Njc.

X2 = X.transpose() for row in X2: Njc.append(dot(row,row.transpose())) 

However, when I run my program, the results are not single. They are similar: (0, 0) 355

(0, 0) 295

(0, 0) 15

(0, 0) 204

(0, 0) 66

....

Unfortunately, my sparse matrix is โ€‹โ€‹so large that I cannot turn it into a dense matrix (my memory will explode). Is there a way to get only numbers on the right without pairs on the left?

+4
source share
1 answer

dot returns a sparse matrix. To highlight a single value in a sparse matrix, you can use .todense().item() :

 Njc.append((np.dot(row, row.transpose())).todense().item()) 
+3
source

Source: https://habr.com/ru/post/1446813/


All Articles