How to efficiently calculate a weighted sum of 3 dimensional matrix through a vector in matlab
Show older comments
A is a 3 dimensional matrix (M*N*K), b is a vector with length K. I need to calculate
3 Comments
Dyuman Joshi
on 17 Nov 2023
Moved: Dyuman Joshi
on 17 Nov 2023
%Random data
A = rand(3,4,5);
b = rand(5,1);
C = sum(A.*reshape(b,1,1,[]), 3)
Hancheng Zhu
on 20 Nov 2023
Matt J
on 20 Nov 2023
@Hancheng Zhu If that means you've settled on one of the answers below, please Accept-click one of them.
Accepted Answer
More Answers (1)
Matt J
on 17 Nov 2023
C=tensorprod(A,b,3,1)
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!