[go: up one dir, main page]

0% found this document useful (0 votes)
26 views1 page

Statistics

This document contains a function to calculate various statistical measures of a numpy array including the mean, median, standard deviation, variance, mode, and interquartile range. The function takes in a numpy array and returns these measures with rounding to two decimal places.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Statistics

This document contains a function to calculate various statistical measures of a numpy array including the mean, median, standard deviation, variance, mode, and interquartile range. The function takes in a numpy array and returns these measures with rounding to two decimal places.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

n=len(arr)
mean=np.mean(arr)
median=np.median(arr)
std_deviation=round(np.std(arr),2)
variance=round(np.var(arr),2)
mode=int(stats.mode(numbers)[0])
iqr=(np.percentile(arr,75,interpolation='midpoint')-
np.percentile(arr,25,interpolation='midpoint'))

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

You might also like