Efficient implementation of a sequence of matrix-vector products / specific “tensor”-matrix product
问题 I have a special algorithm where as one of the lasts steps I need to carry out a multiplication of a 3-D array with a 2-D array such that each matrix-slice of the 3-D array is multiplied wich each column of the 2-D array. In other words, if, say A is an N x N x N matrix and B is an N x N matrix, I need to compute a matrix C of size N x N where C(:,i) = A(:,:,i)*B(:,i); . The naive way to implement this is a loop, i.e., C = zeros(N,N); for i = 1:N C(:,i) = A(:,:,i)*B(:,i); end However, loops