Element-wise matrix multiplication for multi-dimensional array
问题 I want to realize component-wise matrix multiplication in MATLAB, which can be done using numpy.einsum in Python as below: import numpy as np M = 2 N = 4 I = 2000 J = 300 A = np.random.randn(M, M, I) B = np.random.randn(M, M, N, J, I) C = np.random.randn(M, J, I) # using einsum D = np.einsum('mki, klnji, lji -> mnji', A, B, C) # naive for-loop E = np.zeros(M, N, J, I) for i in range(I): for j in range(J): for n in range(N): E[:,n,j,i] = B[:,:,i] @ A[:,:,n,j,i] @ C[:,j,i] print(np.sum(np.abs(D