I am required to multiply 2 csr matrices with shapes A : (385019, 72) B : (72, 385019). I do see that the # of columns of A is 72 and thats exactly the number of rows in B. Yet when I perform sparse.csr_matrix(A).multiply(sparse.csr_matrix(A))
I get ValueError: inconsistent shapes
I have been through other posts but nothing has helped me yet.
Very large matrices using Python and NumPy
Asked
Active
Viewed 1,645 times
1

vku
- 175
- 1
- 1
- 10
1 Answers
6
The multiplication you are looking for is called "dot product" and in python you can do that as follows
sparse.csr_matrix(A) * sparse.csr_matrix(B)
However, the multiplication that you are using sparse.csr_matrix(A).multiply(sparse.csr_matrix(A))
in the problem you described is called "Point-wise multiplication by another matrix, vector, or scalar". This means that every element of A will be multiplied by every element of B if both A and B are matrices; in this case size of A and B must be same. If B is a scalar then every element of A will be multiplied by B.

Mohsin
- 536
- 6
- 18
-
2Thanks a lot Mohsin :) That helped. – vku Feb 14 '18 at 17:06
-
1it was my pleasure to help – Mohsin Feb 14 '18 at 20:29