# numpy.random.rand () in Python

|

numpy.random.rand (d0, d1,…, dn): creates an array of the given shape and fills it with random values.
Parameters :

`  d0, d1, ..., dn:  [int, optional] Dimension of the returned array we require, If no argument is given a single Python float is returned. `

Return:

` Array of defined shape, filled with random values. `

Code 1: randomly build a one-dimensional array

 ` # Python program illustrating ` ` # numpy.random.rand () method `   ` import ` ` numpy as geek `   ` # 1D Array ` ` array ` ` = ` ` geek.random.rand (` ` 5 ` `) ` ` print ` ` (` ` "1D Array filled with random values:" ` `, array); `

Output:

` 1D Array filled with random values: [0.84503968 0.61570994 0.7619945 0.34994803 0.40113761] `

Code 2: random 2D array

 ` # Python program illustrating ` ` # numpy.random.rand () method `   ` import ` ` numpy as geek `   ` # 2D Array ` ` array ` ` = ` ` geek.random.rand (` ` 3 ` `, ` ` 4 ` `) ` ` print ` ` (` `" 2D Array filled with random values: "` `, array); `

Output:

` 2D Array filled with random values: [[0.94739375 0.5557614 0.69812121 0.86902435] [0.94758176 0.22254413 0.21605843 0.44673235] [0.61683839 0.40570269 0.34369248 0.46799524]] `

Code 3: random strong>

 ` # Python program illustrating ` ` # numpy.random.rand () method `   ` import ` ` numpy as geek ` ` `  ` # 3D Array ` ` array ` ` = ` ` geek.random.rand (` ` 2 ` `, ` ` 2 , 2 ) `` print ( "3D Array filled with random values:" , array); `

Output:

` 3D Array filled with random values: [[[0.97942627 0.01068711] [0.35749073 0.22484643]] [[0.99733022 0.8029555] [0.44111692 0.90537128]]] `

Notes:
These codes will not work for online ID. Please run them on your systems to see how they work.
,

## Shop Learn programming in R: courses

\$ Best Python online courses for 2022

\$ Best laptop for Fortnite

\$ Best laptop for Excel

\$ Best laptop for Solidworks

\$ Best laptop for Roblox

\$ Best computer for crypto mining

\$ Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method