|
From: | Paul Roberts |
Subject: | Re: generating sparse matricies |
Date: | Sat, 1 Oct 2005 13:28:04 -0700 |
Søren Hauberg a écrit :
>I can't remember if this works in 2.164, but in 2.9.3 you can just use
>'sprand'
>
>/Søren
>
>fre, 30 09 2005 kl. 23:07 -0700, skrev Paul Roberts:
>
>
>>Hello,
>>
>>I am using Octave 2.1.64. I would like to iteratively build a sparse
>>matrix uring code like:
>>
>>X = sparse(10000,1000);
>>for j=1:1000
>>X(:, j) = rand(10000,1) < 0.01;
>>end
>>
>>
Furthermore, if you use a structure like the above in octave 2.9.x (or
even matlab for the above case, use spalloc in matlab for the above),
you'll reallocate the memory for the sparse matrix at each iteration of
the for-loop. Therefore, this is likely to be slow.. Its much better to
create three vectors for the row, column and value and create the matrix
directly. See section 22.1.2 of the manual in 2.9.3 version of octave.
I've written some patchy documentation for the sparse stuff that is in
section 22.
Note the assign function isn't implemented in the octave-forge sparse
toolbox which is what made me start implementing a new sparse
implementation in the first place. So the above won't work, though
sprand will.
Cheers
David
[Prev in Thread] | Current Thread | [Next in Thread] |