How to do some tensor multiplication without using for loop in python?
It turns out the answer is incredibly simple. I just used np.matmul (X,Y) to achieve the result I wanted.
Say I have two arrays X=[A,B,C] and Y=[D,E,F], where each element is a 3 by 3 matrix. I would like to make an array Z=[AD,BE,CF] without using for loop. What should I do?
I have tried using np.tensordot(X,Y,axis=1) but it returns 9 products [[AD,AE,AF],[BD,BE,BF],[CD,CE,CF]]. the troublesome thing is that the matrix size for each element must be the same as the array length, say for 3 by 3 matrix, X and Y should have 3 elements each.