[Numpy-discussion] sparse matrix dot product

Nicolas Rougier Nicolas.Rougier at loria.fr
Thu May 28 10:14:12 EDT 2009


Hi,

I'm now testing dot product and using the following:

import numpy as np, scipy.sparse as sp

A = np.matrix(np.zeros((5,10)))
B = np.zeros((10,1))
print (A*B).shape
print np.dot(A,B).shape

A = sp.csr_matrix(np.zeros((5,10)))
B = sp.csr_matrix((10,1))
print (A*B).shape
print np.dot(A,B).shape

A = sp.csr_matrix(np.zeros((5,10)))
B = np.zeros((10,1))
print (A*B).shape
print np.dot(A,B).shape


I got:

(5, 1)
(5, 1)
(5, 1)
(5, 1)
(5, 1)
(10, 1)


Obviously, the last computation is not a dot product, but I got no
warning at all. Is that the expected behavior ?


By the way, I wrote a speed benchmark for dot product using the
different flavors of sparse matrices and I wonder if it should go
somewhere in documentation (in anycase, if anyone interested, I can post
the benchmark program and result).

Nicolas







More information about the NumPy-Discussion mailing list