sweep of tensor products

2 visualizzazioni (ultimi 30 giorni)
Olivier
Olivier il 5 Nov 2024
Commentato: Olivier il 6 Nov 2024
Hello,
I have two matrces A of dimension c x n and B of dimension c x l with c >> n and c >> l
I would like to calculate the tensor C of dimesion c x (n x l) wht C_i,j,k = A_i_j * B_i_k
Is there a way to imrpove the following code ?
Thank you in advance,
c = 100;
n = 5;
l = 10;
A = rand(c, n);
B = rand(c, l);
C = nan([ c n l] );
for ii = 1:c
C(ii,:,:) = tensorprod(A(ii,:),B(ii,:));
end

Risposta accettata

Bruno Luong
Bruno Luong il 5 Nov 2024
Modificato: Bruno Luong il 5 Nov 2024
Strictly speaking you do not compute a tensor product.
c = 100;
n = 5;
l = 10;
A = rand(c, n);
B = rand(c, l);
C = A .* reshape(B, c, 1, l);
size(C)
ans = 1×3
100 5 10
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  3 Commenti
Matt J
Matt J il 6 Nov 2024
Strictly speaking you do not compute a tensor product.
It is essentially, a Khatri-Rao product.
Olivier
Olivier il 6 Nov 2024
Actually, my original intent is to calculate this (Einstein notation)
C_j,k,l = A_i,j * B_i,k * C_i,l
I calculated first B_i,k * C_i,l and then proceeded to a tensor product.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Linear Algebra in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by