[SciPy-user] Random sparse matrices

Nathan Bell wnbell@gmail....
Fri Apr 25 13:56:21 CDT 2008

On Fri, Apr 25, 2008 at 9:17 AM, Mico Filós <elmico.filos@gmail.com> wrote:
> Dear all,
>  here is my first attempt. I basically use Nathan's suggested
>  functions, and _rand_sparse incorporates the algorithm proposed by
>  David to avoid ending up with fewer nonzero elements than expected. It
>  is the first time I propose an update
>  for scipy code, so be lenient with me :)

Thanks for your contribution Mico.  Unfortunately, the line
   rand_seq = permutation(m*n)[:nnz]
is a *dense* MxN operation, so we cannot use this approach.

MATLAB's sprand() and sprandn() have the same artifact as the code I
presented, so I don't know whether it's worth trying to avoid the
duplicate entries.

If you can figure out an economial way to produce exactly nnz elements
in the result, then we would probably use it.  I wasn't able to come
up with anything better than the MATLAB approach.

Nathan Bell wnbell@gmail.com

More information about the SciPy-user mailing list