numpy.random.rand() function in Python

Spread the love

numpy.random.rand(): This function returns Random values in a given shape. It Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

Syntax: numpy.random.rand(d0, d1, …, dn)

Parameters:
d0, d1, …, dn : int, optional
The dimensions of the returned array, should all be positive. If no argument is given a single Python float is returned.

Returns:
out : ndarray, shape (d0, d1, …, dn)
Random values.

#Example program on numpy.random.rand() function

import numpy as np # one dimensional array print(np.random.rand(10)) # two dimensional array print(np.random.rand(2,5)) # three dimensional array print(np.random.rand(3,3,3))

Output:

[ 0.27970717  0.74051427  0.06781617  0.06965978  0.01146766  0.13030936
  0.25948311  0.76907386  0.72382275  0.29564673]
[[ 0.27195449  0.5744164   0.0032461   0.36502227  0.21478035]
 [ 0.57526485  0.75684874  0.98164689  0.97893362  0.62642495]]
[[[ 0.29016941  0.12679977  0.59884554]
  [ 0.81177943  0.51168175  0.30511396]
  [ 0.18430922  0.0151866   0.05515292]]

 [[ 0.53368394  0.90000968  0.8417444 ]
  [ 0.48896971  0.44978217  0.12383014]
  [ 0.89102444  0.33451971  0.4701923 ]]

 [[ 0.6536559   0.65463112  0.12052995]
  [ 0.73898131  0.57329045  0.81933027]
  [ 0.76714976  0.23212792  0.18766463]]]

 

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *