First page Back Continue Last page Overview Graphics

Multidemensional Random Numbers

Creating multi-dimensional random number arrays with reshape:

>>> np.random.rand(9).reshape((3,3))

array([[ 0.07037939, 0.70965635, 0.22702356],

[ 0.61935471, 0.66461758, 0.95855922],

[ 0.2374523 , 0.70934261, 0.66138303]])

or directly with rand():

>>> np.random.rand(3,3)

array([[ 0.75312235, 0.58058764, 0.74118194],

[ 0.78343227, 0.57490163, 0.01243915],

[ 0.40872102, 0.21864152, 0.74429928]])

>>> np.random.rand(3,2)

array([[ 0.85136361, 0.66083836],

[ 0.36800596, 0.22547915],

[ 0.95294589, 0.1333564 ]])