Import As From Import Import: Problem 1
Import As From Import Import: Problem 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
'''
mean=round(np.mean(arr),2)
median=round(np.median(arr),2)
std_deviation=round(np.std(arr),2)
variance=round(statistics.pvariance(arr),2)
mode=round(statistics.mode(arr),2)
iqr=round(stats.iqr(arr),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))
Problem2
def comb_perm(arr):
#Write your code here
'''
Input: arr : numpy array
Return : no_of_comb,no_of_perm : Integer
'''
no_of_comb= len(list(combinations(arr,2)))
no_of_perm= len(list(permutations(arr,2)))
return no_of_comb,no_of_perm
if __name__=='__main__':
array1=[]
n=int(input())
for i in range(n):
array1.append(input())
narray1=np.array(array1)
print(comb_perm(narray1))
Example
from scipy import stats
import numpy as np
import statistics
data ={"A": 90,"B": 86,"C":70,"D":95,"E":95,"F":95,"G":95}
values = list(data.values())
print("Mean")
print(np.mean(values))
print("Median")
print(np.median(values))
print("Mode")
print(statistics.mode(values))
print("Standard Deviation")
print(np.std(values))
print("Variance")
print(np.var(values))
print("range")
print(stats.iqr(values))```
Problem3
import math
def dancers():
'''
output: ans : Integer
'''
#Write your code here
#Assign your value to variable ans
boy=math.factorial(6)/((math.factorial(3))*math.factorial(3))
girl=math.factorial(5)/((math.factorial(2))*math.factorial(3))
ans=boy*girl
return int(ans)
if __name__=='__main__':
print(dancers())
Problem4
def binomial():
'''
output: ans : Float
'''
#Write your code here
#Assign the probability value to the variable ans
#Round off to 2 decimal places
p=0.6
n=4
r=0
a = stats.binom.pmf(r, n, p)
ans =round(1-a,2)
return ans
if __name__=='__main__':
print(binomial())
Problem5
def poisson():
'''
output: ans : Float
'''
#Write your code here
#Assign the probability value to the variable ans
#Round off to 2 decimal places
ans=round(stats.poisson.pmf(15,10),2)
return ans
if __name__=='__main__':
print(poisson())