Probability and Statistics - Statistical Measures
In this scenario, you will be exploring the most commonly used statistical measures
- Mean
- Median
- Standard Deviation
- Variance
- Mode
- Inter Quartile Range
Function Description
Function Name: measures()
1. Input:
- arr - Numpy array
2. Output:
- mean, median, std_deviation, variance, mode, iqr : tuple of results
- Note: Every value must be rounded off to 2 decimal places
Answer:
import numpy as np
from scipy import stats
import statistics
def measures(arr):
#Write your code here
'''
Input: arr : numpy array
Return : mean,median,std_deviation,variance,mode,iqr : float
Note:
1. Assign the values to designated variables
2. Round off to 2 decimal places
'''
q3, q1 = np.percentile(arr, [75 ,25])
arr = np.array(arr)
mean = round(np.mean(arr),2)
median = round(np.median(arr),2)
std_deviation=round(np.std(arr),2)
variance=round(np.var(arr),2)
mode=round(statistics.mode(arr),2)
iqr=round((q3-q1),2)
return mean,median,std_deviation,variance,mode,iqr
if __name__=='__main__':
array1=[]
n=int(input())
for i in range(n):
array1.append(float(input()))
narray1=np.array(array1)
print(measures(narray1))
Click on the image to check test cases:
No comments:
Post a Comment
If you have any doubts, Please let us know.