Write a Program to calculate Mean, Median, Mode , Standard Deviation, and Variance of an array.
Coding
Import the Packages numpy,statistics
Declare a numpy array with values 9.2,10.7,6.8,9,3.4,5.7,5.7
Calculate Mean, Median, Standard Deviation and Variance with the built-in functions of Numpy Package.
Calculate Mode with the built-in function of Statistics Package.(Calculation of mode must print the value which has the greatest number of occurrences in the array)
Display the output in the following order
Mean
Median
Standard Deviation
Variance
Mode
Answers
Answered by
2
Python Program
Mean
It is the average of all numbers and is sometimes called the arithmetic mean.
n_num = [9.2, 10.7, 6.8, 9, 3.4,5.7,5.7]
n=len(n_num)
get_sum =sum(n_num)
mean = get_sum/n
print("mean/avarage is: "+str(mean))
output:
Mean / Average is: 7.214
Median:
The middle number in a group of numbers.
n_num =[9.2, 10.7, 6.8, 9, 3.4,5.7,5.7]
n=len(n_num)
n_num.sort()
if n% 2 ==0:
median1 = n_num[n//2]
median1 = n_num[n//2-1]
median =(median1+median2)/2
else
median = n_num[n//2]
print("median is:" +str(median))
output:
Median is: 9
Mode
The mode is the number that occurs most often within a set of numbers.
n_num = [9.2, 10.7, 6.8, 9, 3.4,5.7,5.7]
n = len(n_num)
data = Counter(n_num)
get_mode = dict(data)
mode = [k for k, v in get_mode.items() if v ==max(list(data.values()))]
if len(mode) == n
get_mode = "No mode found"
else
get_mode ="mode is /are:"+','.join(map(str,mode))
print(get_mode)
output
Mode is / are: 5.7
To Learn More...
- brainly.in/question/14751633
Similar questions