Numpy library in python | numpy python 3

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()

Example 1:-

import numpy as np
normal_array=np.random.normal (5, 0.5, 10)
print(normal_array)
Output:-
[5.56171852]                       
Example 2:-
print(np.min(normal_array))
           print(np.max(normal_array))
           print(np.mean(normal_array))
           print(np.median(normal_array))
           print(np.std(normal_array))
Output:-
4.46
5.61
4.93
4.83

1) The numpy.amin () and numpy.amax () :-

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]

2. numpy.ptp() function:-

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]

3. numpy.percentile () function:-

The syntax is as follows,
numpy.percentile (input, q, axis)
Parameters:-
input:-It will denote the input array.
q:-It denotes percentile (1-100) which is calculated of array element.
axis:-The axis along the percentile which is calculated.
Example:-
import numpy as np
a=np.array ([2, 10, 20], [80, 43, 31], [22, 43, 10])
print(“Array: \n”, a)
print(“\npercentile along axis 0”, np.percentile(a,10,0))
print(“percentile along axis 1”, np.percentile(a,10,1))
Output:-
array= ([2 10 20][80 43 31][22 43 10])
Percentile along axis 0[6. 16.6 12.]
Percentile along axis 1[3.6.  33.4 12.4]

4. numpy.median () function:-

The median is defined as value used to separate higher range of data sample with the lower range of data sample.
It is also used to calculate median of one dimensional or multidimensional array.
import numpy as np
a=np.array ([1, 2, 3], [4, 5, 6], [7, 8, 9])
print(“array: \n”, a”)
print(“\n Median of array along axis 0:”,np.median(a,0))

5. numpy.mean() function:-

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))

6. numpy.average () function:-

The numpy.average function is calculated and used to find the weighted average of axis and multidimensional array where their weights are given.
Example:-
import numpy as np
a=np.array ([1, 2, 3], [4, 5, 6], [7, 8, 9])
print(“Array: \n”, a”)
print(“Average of array along axis 1:”,np.median(a,1))

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India