I need to generate a sparse random matrix in Python with all values in the range [-1,1]
with uniform distribution. What is the most efficient way to do this?
I have a basic sparse random matrix:
from scipy import sparse
from numpy.random import RandomState
p = sparse.rand(10, 10, 0.1, random_state=RandomState(1))
And this gives me values in [0,1]
:
print p
(0, 0) 0.419194514403
(0, 3) 0.0273875931979
(1, 4) 0.558689828446
(2, 7) 0.198101489085
(3, 5) 0.140386938595
(4, 1) 0.204452249732
(4, 3) 0.670467510178
(8, 1) 0.878117436391
(9, 0) 0.685219500397
(9, 3) 0.417304802367
It would be good to have an in-place solution or something that doesn't require blowing it up to a full matrix since in practice I will be using very large dimensions. It surprises me there are not some quick parameters to set for sparse.rand
itself.
Aucun commentaire:
Enregistrer un commentaire