Sparse Array with reshape

6 vues (au cours des 30 derniers jours)
Amit Chakraborty
Amit Chakraborty le 9 Oct 2021
I have a similar type of problem Yesterday but that is with non-sparse matrix. I am very newly dealing with these sparse matrix stuffs.
X = sparse(rand(360, 4^3));
Y = sparse(rand(10, 4^3));
FF = reshape(X, 36, 10, []);
TT = reshape(Y, 1, 10, []);
Result = reshape(FF .* TT, 360, []);
Error: Error using reshape.ND sparse arrays are not supported.
**** My actual sparse matrix size is very big so I cannot use "full" fuction there. *******
Explanation what I actually want :
Here, the size of X and Y is 360x1 and 10x1 sparse matrix respectively. I want to multiply in such a manner that the : first 36 row of F will be multiplied by the first row of T and next 36 row of F will be multiplied by second row of T and continue the like this. And the resultant Matrix will have the size (360,4^3). I am getting error because I know that 3D array cannot be reshaped in MATLAB.

Réponse acceptée

Matt J
Matt J le 9 Oct 2021
Modifié(e) : Matt J le 9 Oct 2021
Consider downloading ndSparse.
FF = ndSparse.sprand( [36, 10,4^3],0.2);
TT = ndSparse.sprand([1,10, 4^3], 0.2);
Result = sparse2d( reshape(FF .* TT, 360, []) );
whos FF TT Result
Name Size Bytes Class Attributes FF 36x10x64 67520 ndSparse sparse Result 360x64 12312 double sparse TT 1x10x64 2384 ndSparse sparse
  1 commentaire
Amit Chakraborty
Amit Chakraborty le 10 Oct 2021
Thank u so much @Matt J!!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Translated by