File Exchange

image thumbnail

Tensor matrix multiply

version (2.58 KB) by Oliver Woodford
Matrix multiplication over tensor arrays (i.e. arrays of matrices), with matrix transposition.


Updated 24 Feb 2017

View License

C = tmult(A, B) is equivalent to:
sz = [size(B) 1];
sz(1) = size(A, 1);
C = zeros(sz);
for a = 1:prod(sz(3:end))
C(:,:,a) = A(:,:,a) * B(:,:,a);

but is completely vectorized, so much faster. Tmult also supports bsxfun-style expansion of singular dimensions where appropriate, such that tmult(rand(4, 3, 10), rand(3, 2)) yields a 4x2x10 output.

Cite As

Oliver Woodford (2020). Tensor matrix multiply (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux