[Numpy-discussion] random seed replicate 2d randn with 1d loop
Keith Goodman
kwgoodman at gmail.com
Mon May 23 15:41:55 EDT 2011
On Mon, May 23, 2011 at 12:34 PM, <josef.pktd at gmail.com> wrote:
> Obviously I was working by columns, using a transpose worked, but
> rewriting to axis=1 instead of axis=0 which should be more efficient
> since I had almost all calculations by columns, I needed
> params = map(lambda x: np.expand_dims(x, 1), params)
> to get around broadcast errors that work automatically with axis=0
Here's another way to work by columns (note the input parameter oder='F'):
>> rs = np.random.RandomState([1,2,3])
>> rs.randn(9).reshape(3,3,order='F')
array([[ 0.89858245, -0.05663392, 0.82495129],
[ 0.25528877, 0.54721555, 0.17252144],
[ 0.95172625, 0.11512385, 0.74570118]])
>> rs = np.random.RandomState([1,2,3])
>> rs.randn(3)
array([ 0.89858245, 0.25528877, 0.95172625])
>> rs.randn(3)
array([-0.05663392, 0.54721555, 0.11512385])
>> rs.randn(3)
array([ 0.82495129, 0.17252144, 0.74570118])
More information about the NumPy-Discussion
mailing list