[SciPy-User] Dot product of sparse vector and dense matrix

Peter Prettenhofer peter.prettenhofer at gmail.com
Mon Dec 19 07:00:20 EST 2011


Hi,

I'd like to compute the dot product between a sparse vector `x` and a
dense (numpy) matrix `W` as fast as possible. My `x` is extremely
sparse (dimensionality is about 2**20, nnz about 7) and my `W` is
2**20 times 20. After some benchmarks I found that for `x` being a csr
matrix, `x * W` is much slower than it should be (about 52.7 ms)
whereas if I represent `x` as a dense numpy array I get (4.5 ms). If I
convert both `x` and `W` to csc format I'm in the same ballmarks as
the all dense version (5.12 ms).

The dot product of a sparse vector and a dense matrix should be much
faster than the dot product of a sparse vector and a sparse matrix -
does scipy provide a lowlevel api for sparse-dense dot products?

thanks,
 Peter

-- 
Peter Prettenhofer



More information about the SciPy-User mailing list