Your question at first confused me, because for my version of scipy A.dot(B) and np.dot(A, B) both work fine; the sparse matrix .dot method simply overrides np.dot . However, it seems that this function has been added to this pull request and is not available in scipy versions older than 0.14.0. I assume you have one of these older versions.
Here are some test data:
import numpy as np from scipy import sparse A = np.random.randn(1000, 2000) B = sparse.rand(2000, 3000, format='csr')
For scipy versions> = 0.14.0 you can simply use:
C = A.dot(B) C = np.dot(A, B)
For versions <0.14.0 , both of them will raise the value of ValueError :
In [6]: C = A.dot(B)
Instead, you can use one of:
As you can see, there is basically no difference in performance, although I personally think the second version is more readable.
Update:
As @ shaoyl85 pointed out, you can simply use the * operator instead of directly calling the __rmul__() method:
Matrices seem to have higher priority in determining the behavior of the * operator than ndarrays. This is a potential opportunity for those of us who are more used to ndarrays (where * means elemental multiplication).
ali_m source share