Skip to content

Commit

Permalink
DOC: add a sparse random docstring example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbrc committed Apr 2, 2015
1 parent 77af8f4 commit e040094
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scipy/sparse/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,22 @@ def random(m, n, density=0.01, format='coo', dtype=None,
sampled using the same random state as is used for sampling
the sparsity structure.
Examples
--------
>>> from scipy.sparse import construct
>>> from scipy import stats
>>> class CustomRandomState(object):
... def randint(self, k):
... i = np.random.randint(k)
... return i - i % 2
>>> rs = CustomRandomState()
>>> rvs = stats.poisson(25, loc=10).rvs
>>> S = construct.random(3, 4, density=0.25, random_state=rs, data_rvs=rvs)
>>> S.A
array([[ 36., 0., 33., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 36., 0.]])
Notes
-----
Only float types are supported for now.
Expand Down

0 comments on commit e040094

Please sign in to comment.