Reshape large sparse matrices

Hi, I need to reshape large sparse matrices into vectors by concatenating the rows. Large in my case means square matrices up to Nrows=20000, the density of such matrices is very small, with only about Nrows non zero elements. However, when I try to use reshape to build the corresponding vector (predefined to be sparse also), I don't get any error but the calculation take very long, which seems to me strange since in fact only a few values are non-zero. The only explanation I have for this is that reshape does not treat sparse matrices as sparse. So, is there any way to do the same faster? I have a workaround but it is not so fast and more importantly it is not at all elegant.

1 件のコメント

Jan
Jan 2011 年 7 月 6 日
Please post a code snippet, which reproduces the problem.

サインインしてコメントする。

回答 (1 件)

the cyclist
the cyclist 2011 年 7 月 6 日

0 投票

The following code, which reshapes a large sparse array, is very fast on my machine:
N = 20000;
s = speye(N);
rs = reshape(s,[N*N,1]);
I second Jan's suggestion to supply a code snippet, if you can.

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2011 年 7 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by