← Back to team overview

larry-discuss team mailing list archive

rand and randn

 

To test something new at the command line I often set things up with:

    >> import numpy as np
    >> y = larry(np.random.rand(500,500))

That gets to be pain after a while.

So I added rand and randn to the la package. Here are the examples
from the rand doc string:

    A single random sample:

    >>> la.rand()
    0.64323350463488804

    A shape (2, 2) random larry:

    >>> la.rand(2,2)
    label_0
        0
        1
    label_1
        0
        1
    x
    array([[ 0.09277439,  0.94194077],
           [ 0.72887997,  0.41124147]])

    A shape (2, 2) random larry with given labels:

    >>> la.rand(label=[['row1', 'row2'], ['col1', 'col2']])
    label_0
        row1
        row2
    label_1
        col1
        col2
    x
    array([[ 0.3449072 ,  0.40397174],
           [ 0.7791279 ,  0.86084403]])

    Results are repeatable if you set the state of the random number generator
    outside of la.rand:

    >>> import numpy as np
    >>> rs = np.random.RandomState([1, 2, 3])
    >>> la.randn(randn=rs.randn)
    0.89858244820995015
    >>> la.randn(randn=rs.randn)
    0.25528876596298244
    >>> rs = np.random.RandomState([1, 2, 3])
    >>> la.randn(randn=rs.randn)
    0.89858244820995015
    >>> la.randn(randn=rs.randn)
    0.25528876596298244