Assume I have an array a of matrices, e.g. of shape (N, 3, 3) = N 3x3 matrices and an array b of shape (i, 3, k).
I want these behaviors for the dot product a * b
- If
i = N, the result should be a(N, 3, k)array where the first element isa[0].dot(b[0]), the seconda[1].dot(b[1]), and so on. - If
i = 1, then each element ofamust be dot multiplied byb[0]and the resulting shape should be again(N, 3, k).
If I try to just use numpy.dot() the result is almost good but the resulting shapes are not what I expect. Is there a way to do this easily and efficiently and make it general for any dimension?