I'm using Python, Numpy and Scipy packages to do matrix computations. I am attempting to perform the calculation X.transpose() * W * X
where X is a 2x3 dense matrix and W is a sparse diagonal matrix. (Very simplified example below)
import numpy
import scipy.sparse as sp
X = numpy.array([[1, 1, 1],[2, 2, 2]])
W = sp.spdiags([1, 2], [0], 2, 2).tocsr()
I need to find the product of the Dense Matrix X.transpose and sparse matrix W.
The one method that I know of within scipy does not accept a sparse matrix on the right hand side.
>>> sp.csr_matrix.dot(X.transpose(), W)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method dot() must be called with csr_matrix instance as first argument (got ndarray instance instead)
Is there a way to multiply a sparse and dense matrix where the sparse matrix is the term on the right within scipy? If not, what is the best way to do this without turning my W into a dense matrix?