Dot product of tensor
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Leonardo Mutti
le 6 Avr 2022
Commenté : Leonardo Mutti
le 6 Avr 2022
Hi, I have two tensors A and B, of sizes (ma, na, 3), and (mb, nb, 3).
I would like to create C of size(ma, na, mb, nb) with C(i,j,k,h) = dot(A(i,j,:),B(k,h,:));
What is the fastest and most memory efficient way of achieving this? Many thanks!
0 commentaires
Réponse acceptée
Bruno Luong
le 6 Avr 2022
Modifié(e) : Bruno Luong
le 6 Avr 2022
If you have the R2022a, a single statement will do
A=rand(2,3,3);
B=rand(4,5,3);
C=tensorprod(A,B,3);
size(C)
3 commentaires
Bruno Luong
le 6 Avr 2022
I don't know what you meant by "sums" but MATLAB auto-expansion and reshape is like tensor operators
A=rand(2,3,3);
B=rand(4,5,3);
C = sum(A,3) + reshape(sum(B,3),[1 1 size(B,1) size(B,2)])
% or this?
C = reshape(A, [size(A,1) size(A,2) 1 1 size(A,3)]) + ...
reshape(B, [1 1 size(B)])
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!