Numpy library in python : The numpy provide statistical function used to perform some statistical data analysis. In this we perform the statistical calculation for functions that provide library like averages, variance and histogram. The average () will compute the average in array that function can have axis parameter. The numpy is useful for the statistical function for finding minimum, maximum and variance in the array element list.
Function |
Numpy |
Min |
np.min() |
Max |
np.max() |
Mean |
np.mean() |
Median |
np.median() |
Standard deviation |
np.std() |
They are used to find the minimum and the maximum value of array along with the specified axis.
Example:-
import numpy as np
a=np.array ([[2, 10, 20], [80, 43, 31], [22, 43, 10]])
print(“The original array: \n”)
print(a)
print(“\n The minimum element among the array:” np.amin(a,0))
print(“\n The minimum element among the array:” np.amax(a,0))
print(“\n The minimum element among the column of array:” np.amin(a,1))
print(“\n The maximum element among the column array:” np.amax(a,1))
Output:-
[[2 10 20] [80 43 31][22 43 10]]
The maximum element among the array:-2
The maximum element among the array:-80
The maximum element among the rows of array: [2 10 10]
The maximum element among the rows of array: [80 43 31]
The minimum element among the rows of array: [2 31 10]
The minimum element among the rows of array: [20 80 43]
The function is derived from name called peak to peak and used to return range of values along the axis.
Example:-
import numpy as np
a=np.array ([2, 10, 20], [80, 43, 31], [22, 43, 10])
print(“Orignal array: \n”,a)
print(“\nptp value along axis 1:”, np.ptp(a,1))
print(“ptp value along axis 0:”, np.ptp(a,0))
Output:-
array: [[2 10 20][80 43 31][22 43 10]]
ptp value along axis 1: [18 49 33]
ptp value along axis 0: [78 33 21]
The function can be calculated by adding the items of array and dividing it by number of array elements.
import numpy as np
a=np.array ([1, 2, 3], [4, 5, 6], [7, 8, 9])
print(“Array: \n”, a”)
print(“Mean of array along axis 0:”,np.median(a,0))