How to efficiently calculate a weighted sum of 3 dimensional matrix through a vector in matlab
4 ビュー (過去 30 日間)
古いコメントを表示
A is a 3 dimensional matrix (M*N*K), b is a vector with length K. I need to calculate
, which is a 2 dimensional matrix (M*N). But i don't want to write it by a explicit summation because it is too slow. Is there any way to calculate it efficiently through matlab? Please attach the code if convenience.
3 件のコメント
Matt J
2023 年 11 月 20 日
@Hancheng Zhu If that means you've settled on one of the answers below, please Accept-click one of them.
採用された回答
Bruno Luong
2023 年 11 月 17 日
編集済み: Bruno Luong
2023 年 11 月 17 日
This uses matrix multiplication so it should be well optimized and fast.
[m,n] = size(A, [1 2]);
C = reshape(A,m*n, []) * B(:);
C = reshape(C, m, n);
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!