# rand vs normal in Numpy.random in python

NumPy | Python Methods and Functions

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

Code 2: random construction of a one-dimensional array using Gaussian distribution

 ` # Python program illustrating ` ` # numpy.random.normal () method ` ` `  ` import ` ` numpy as geek `   ` # 1D Array ` ` array ` ` = ` ` geek.random.normal (` ` 0.0 ` `, ` ` 1.0 ` `, ` ` 5 ` `) ` ` print ` ` (` < code class = "string"> "1D Array filled with random values" ` "as per gaussian distribution: "` `, array) ` ` # 3D array ` ` array ` ` = ` ` geek.random.normal (` ` 0.0 ` `, ` ` 1.0 ` `, (` ` 2 ` `, ` ` 1 ` `, ` ` 2 ` `)) ` ` print ` ` (` ` "3D Array filled with random values" ` ` ` ` "as per gaussian distribution:" ` `, array) `

B Output:

` 1D Array filled with random values ​​as per gaussian distribution: [-0.99013172 -1.52521808 0.37955684 0.57859283 1.34336863] 3D Array filled with random values ​​as per gaussian distribution: [[[-0.0320374 2.14977849 ]] [[0.3789585 0.17692125]]] `

Code3: Python program that illustrates graphical representations of random and normal in NumPy

 ` # Python program illustrating ` ` # graphical representation ` ` # numpy .random.normal () method ` ` # numpy.random.rand () method `   ` import ` ` numpy as geek ` ` import ` ` matplotlib.pyplot as plot `   ` Array # 1D according to Gaussian distribution ` ` mean ` ` = ` ` 0 `  ` std ` ` = ` ` 0.1 ` ` array ` ` = ` ` geek.random.normal (` ` 0 ` `, ` ` 0.1 ` `, ` ` 1000 ` `) ` ` print ` ` (` ` "1D Array filled with random values" ` ` "as per gaussian distribution: "` `, array); `   ` # Source code: ` ` # https://docs.scipy.org/doc/numpy- 1.13.0 / reference / ` ` # generated / numpy-random-normal-1.py ` ` count, bins, ignored ` ` = ` ` plot.hist (array, ` ` 30 ` `, normed ` ` = ` ` True ` `) ` ` plot.plot (bins, ` ` 1 ` ` / ` ` (std ` ` * ` ` geek .sqrt (` ` 2 ` ` * ` ` geek.pi)) ` ` * ` ` ` ` geek.exp (` ` - ` ` (bins ` ` - ` ` mean) ` ` * ` ` * ` ` 2 ` ` / ` ` (` ` 2 ` ` * ` ` std ` ` * ` ` * ` ` 2 ` `)), ` ` ` ` linewidth ` ` = ` ` 2 ` `, color ` ` = ` `' r' ` `) ` ` plot.show () `     ` # 1D array built randomly ` ` random_array ` ` = ` ` geek.random.rand (` ` 5 ` `) ` ` print ` ` (` ` "1D Array filled with random values:" ` `, random_array) `   ` plot.plot (random_array) ` ` plot.show () `

Output:

` 1D Array filled with random values ​​as per gaussian distribution: [0.12413355 0.01868444 0.08841698 ..., -0.01523021 -0.14621625 -0.09157214]     1D Array filled with random values: [0.72654409 0.26955422 0.19500427 0.37178803 0.10196284]    `

Important:
In Code 3, graph 1 clearly shows the distribution of Gaussian because it is generated from the values ​​generated by the random.normal () method, thus after being Gaussian.
plot 2 does not follow the distribution, as it is generated from random values ​​generated by the random.rand () method.

Notes:
Code 3 will not work to an online ID. Please run them on your systems to see how they work.
,