Effacer les filtres
Effacer les filtres

adding vector to matrix to create tensor

6 vues (au cours des 30 derniers jours)
Noya Linder
Noya Linder le 24 Juil 2023
Commenté : Steven Lord le 24 Juil 2023
Hi. I have a 10176X10176 matrix and a 10176X1 vector that I want to add to the matrix in order to create a 10176X10176X10176 tensor, without a for loop.
How should I go about that?

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 24 Juil 2023
%Sample example
y = rand(12,12);
z = rand(12,1);
%Change the dimensions of z from mxnx1 to nx1xm
z0 = permute(z,[2 3 1]);
size(z0)
ans = 1×3
1 1 12
%Perform the addition
out = y + z0;
size(out)
ans = 1×3
12 12 12
  1 commentaire
Steven Lord
Steven Lord le 24 Juil 2023
This is a correct answer, but it probably won't work on the original question for practical reasons. Assuming the data is real double data:
numElements = 10176^3;
bytes = 8*numElements;
tb = bytes/(1000^4)
tb = 8.4299
the result would require over 8 terabytes of contiguous memory to store.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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!

Translated by