[SciPy-user] Random sparse matrices

Nils Wagner nwagner@iam.uni-stuttgart...
Tue Apr 22 12:34:40 CDT 2008


On Tue, 22 Apr 2008 19:26:37 +0200
  "Mico Filós" <elmico.filos@gmail.com> wrote:
>>  AFAIK, there is no function like sprandn
> 
> Thanks Nils.
> 
> Could anyone suggest a hint of how to get a random 
>sparse matrix
> without reinventing the wheel (using numpy/scipy 
>functions whenever
> possible).
> 
If you use help (scipy.sparse) you will find the following
example

     >>> from scipy import sparse, linsolve
     >>> from numpy import linalg
     >>> from numpy.random import rand
     >>> A = sparse.lil_matrix((1000, 1000))
     >>> A[0, :100] = rand(100)
     >>> A[1, 100:200] = A[0, :100]
     >>> A.setdiag(rand(1000))

> Is there any reason why 'sprandn' does not exist? (I 
>mean, perhaps
> there is a more general method to do that, I don't 
>know).

> 
> Thanks again
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

  


More information about the SciPy-user mailing list