How to implement Statistics functions in Numpy using Python?
This is a branch of mathematics. It collects the data, analyses it and present it accordingly. It has many methods which is used to find sum, average, minimum , maximum and so on.
Let us implement the list of functions given below…..
- Sum: to find the total of all elements.
- Mean: it find the average value.
- Median :it gives you the middle value after sorting.
- Maximum :this function gives you maximum value of the array.
- Minimum: it provides the minimum value of the array.
- Standard deviation: it finds the standard deviation value.
- Variance: it is the square of the standard deviation.
- Product: it multiplies all elements.
- Cumulative sum: it gives the running total.
- Cumulative product: it finds the running product value.
Program to find values for all functions:
import numpy as np1
s_arr = np1.array([11,12,13,14,15,16])
s_sum= np1.sum(s_arr)
s_prod = np1.prod(s_arr)
s_mean = np1.mean(s_arr)
s_medi = np1.median(s_arr)
s_min = np1.min(s_arr)
s_max = np1.max(s_arr)
s_std = np1.std(s_arr)
s_var = np1.var(s_arr)
s_csum = np1.cumsum(s_arr)
s_psum = np1.cumprod(s_arr)
print("The sum of the array elements are:",s_sum)
print("The product of the array elements are:",s_prod)
print("The mean of the array elements are:",s_mean)
print("The median of the array elements are:",s_medi)
print("The minimum value in the array is:",s_min)
print("The maximum value in the array is:",s_max)
print("The standard deviation of the array elements
are:",s_std)
print("The variance value is:",s_var)
print("The cumulative sum of the array elements
are:",s_csum)
print("The cumulative product of the array elements
are:",s_psum)
Output:
The sum of the array elements are: 81
The product of the array elements are: 5765760
The mean of the array elements are: 13.5
The median of the array elements are: 13.5
The minimum value in the array is: 11
The maximum value in the array is: 16
The standard deviation of the array elements are:
1.707825127659933
The variance value is: 2.9166666666666665
The cumulative sum of the array elements are: [11 23 36 50
65 81]
The cumulative product of the array elements are: [ 11
132 1716 24024
360360 5765760]
This is the way of using statistics functions in Numpy using
Python. Hope, you understood the concept. Keep Coding!!!!
Comments
Post a Comment