How to efficiently calculate a weighted sum of 3 dimensional matrix through a vector in matlab
Ältere Kommentare anzeigen
A is a 3 dimensional matrix (M*N*K), b is a vector with length K. I need to calculate
3 Kommentare
Dyuman Joshi
am 17 Nov. 2023
Verschoben: Dyuman Joshi
am 17 Nov. 2023
%Random data
A = rand(3,4,5);
b = rand(5,1);
C = sum(A.*reshape(b,1,1,[]), 3)
Hancheng Zhu
am 20 Nov. 2023
Matt J
am 20 Nov. 2023
@Hancheng Zhu If that means you've settled on one of the answers below, please Accept-click one of them.
Akzeptierte Antwort
Weitere Antworten (1)
Matt J
am 17 Nov. 2023
C=tensorprod(A,b,3,1)
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!