why does transposing a sparse matrix change its memory requirements
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Matt Fig
2012년 9월 6일
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?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!