Element-wise multiplication of a 3D matrix KxLxM by a 1D vector M
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pim Hacking
am 18 Sep. 2020
Kommentiert: Pim Hacking
am 21 Sep. 2020
Hi all,
the title might be a bit confusing, but I don't know how to properly word this. I want to use matlab's fast matrix multiplications, however I can't figure out how to do it. The following code achieves the desired result with for loops. Any ideas on how to optimize for speed? I'll need to do this on quite large matrices.
Thanks in advance!
K = 2;
L = 10;
M = 13;
A = rand(K,L,M);
B = rand(M,1);
C = zeros(K,L,M);
for k = 1:K
for l = 1:L
C(k,l,:) = squeeze(A(k,l,:)).*B;
end
end
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
KSSV
am 18 Sep. 2020
Anew = reshape(A,K*L,[]) ;
Cnew = Anew.*B' ;
Cnew = reshape(Cnew,K,L,[]) ;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!