Random sqrt std log Functions in Numpy

In this class, We discuss Random sqrt std log Functions in Numpy.

For Complete YouTube Video: Click Here

The reader should have prior knowledge of numpy module. Click here.

The elemental distributions from probability are used in this class.

Check our probability and statistics course for distributions.

Numpy Functions

rand Function

The rand function will randomly generate numbers using a uniform distribution.

The below example shows the program on rand function.

import numpy.random as npr
y=npr.rand(3,2)# take random numbers from uniform distribution [0,1)
print(y)

Output:
[[1.48717102e-01 6.79080620e-02]
 [7.89603984e-02 2.45500870e-01]
 [2.28932249e-04 1.54188073e-01]]

The rand function without shape will return a single element.

import numpy.random as npr
y=npr.rand()# with out shape single value returned
print(y)

Output:
0.79614219707813

randn function

The randn function will randomly select numbers from a standard normal distribution.

The below example shows the program for randn function.

y=npr.randn(3,2)# randn takes values in standard normal distribution
print(y)

Output:
[[ 0.90198251 -1.096846  ]
 [ 0.60154384  0.89030846]
 [-1.39068925  2.22657288]]

randint function

The randint function will randomly select integers using a discrete uniform distribution.

The below example shows a program for randint function.

y=npr.randint(low=2,high=8,size=(3,2))# random integers numbers from low to high discrete uniform distribution
#low inclusive and high exclusive
# if high not given take from 0 to low
print(y)

Output:
[[4 4]
 [7 2]
 [7 4]]

random function

The random function will randomly generate float numbers using a continuous uniform distribution.

The below example shows a program for random function.

y=npr.random((3,2))# return random float numbers in [0,1) interval
#takes continuous uniform distribution
print(y)

Output:
[[0.9857102  0.09313079]
 [0.99141144 0.96707114]
 [0.64332135 0.88594979]]

sqrt Function

The sqrt function will give the square root of the number.

The below example shows the program for sqrt function.

import numpy as np
li=[1,2,4,6]
y=np.sqrt(li)
print(y)

Output:
[1.         1.41421356 2.         2.44948974]

exp Function

The exp function will give the exponential value of a number.

The below example shows the program for exp function.

li=[1,2,4,6]
y=np.exp(li)
print(y)

Output:
[  2.71828183   7.3890561   54.59815003 403.42879349]

log Function

The log function will give the logarithmic value of the number.

The example shows the program for log function.

li=[1,2,4,6]
y=np.log(li)
print(y)

Output:
[0.         0.69314718 1.38629436 1.79175947]

std Function

The std function will give a standard deviation value for a set of numbers.

The below example shows the program for std function.

li=[1,2,4,6]
y=np.std(li)
print(y)

Output:
1.920286436967152