For a current project I have to compute the inner product of a lot of vectors with the same matrix (which is quite sparse). The vectors are associated with a two dimensional grid so I store the vectors in a three dimensional array:
E.g:
X
is an array of dim (I,J,N)
. The matrix A
is of dim (N,N)
. Now the task is to compute A.dot(X[i,j])
for each i,j
in I,J
.
For numpy arrays, this is quite easily accomplished with
Y = X.dot(A.T)
Now I'd like to store A
as sparse matrix since it is sparse and only contains a very limited number of nonzero entries which results in a lot of unnecessary multiplications. Unfortunately, the above solution won't work since the numpy dot doesn't work with sparse matrices. And to the best of my knowledge there is not tensordot-like operation for scipy sparse.
Does anybody know a nice and efficient way to compute the above array Y
with a sparse matrix A
?