In Numpy, say I have a matrix A of dimensions i x j x k, and a matrix B of dimensions k x i. How do I get back a product with dimensions k x i without using a loop?
For example:
Let A = [[[1 2],
[3 4]],
[[5 6],
[7 8]]]
B = [[a b],
[c d]]
I would like to get:
C = [[a+2c 5b+6d],
[3a+4c 7b+8d]]
My current solution is
np.diagonal(np.dot(A, B), axis1=0, axis2=2)
However, the problem is I'm working with a large data set (A and B have huge dimensions) so np.dot(A, B) would lead to MemoryError. Therefore I want to figure out a better way to solve this without computing the dot product.
I have looked into functions like einsum and tensordot but I didn't find what I need (or maybe I missed something). I would appreciate if someone could help me out. Thank you!