Python: Multiplying a list of vectors by a list of matrices as a single matrix operation

Viewed 2135

I have a list of 100 N-dimensional vectors and a list of 100 MxN matrices. So you can think of the two data structures as a 100xN list (or numpy array) and a 100xMxN list (or numpy array).

What I want to do is take the dot product of each vector and its corresponding matrix, such that the output should be 100 M-dimensional matrices (i.e. a 100xM list or numpy array).

However, I'm not really sure how to do this. I don't want to do it iteratively, for obvious reasons about efficiency. I also know it's not basic matrix multiplication. I think I might want to use np.einsum, but I'm not overly familiar with it.

Anyone care to help?

1 Answers
Related