why does transposing a sparse matrix change its memory requirements
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am dealing with a large sparse matrix. I need to turn it into a vector and then transpose it. Because the matrix is sparse, it takes up much, much less memory than it would in full mode. When I use (:) to turn it into a vector, it still takes up little memory. But when I transpose it, it eats up as much memory as it would if it was not sparse. Even though "whos" shows that it is sparse, and nnz() shows that it has the same number of non-zero elements.
Here is a piece of code that will generate the problem. It generates a sparse random matrix, here of dimension 400x400. Then it turns it into a vector, then transposes the vector, then calls whos to see the memory requirements. Compare the memory required for xs_vec and xs_vec_t.
x=randn(400,400); pick=find(x<2); x(pick)=0;
xs=sparse(x);
xs_vec=xs(:); xs_vec_t=xs_vec';
whos
0 comentarios
Respuestas (2)
Matt Fig
el 6 de Sept. de 2012
Yes, MATLAB uses compressed column storage, not compressed row storage. Notice:
>> x = sparse(zeros(1,10000));
>> whos x
Name Size Bytes Class Attributes
x 1x10000 80024 double sparse
>> x = sparse(zeros(10000,1));
>> whos
Name Size Bytes Class Attributes
x 10000x1 32 double sparse
Why do you need to use a row vector?
Ver también
Categorías
Más información sobre Sparse Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!