import numpy as np
import scipy.stats as st
import matplotlib.pyplot as plt
Binomial = st.binom
B = Binomial(5, 0.5) # K, p
B.rvs(size = 10) # random variables / random numbers
array([2, 4, 4, 1, 3, 2, 3, 5, 4, 4])
B.pmf(2) # f( x = 2 |K, p) / probability mass function / density function
0.3125
B.pmf(3)
0.31249999999999994
x = np.arange(6)
f = B.pmf(x)
f
array([0.03125, 0.15625, 0.3125 , 0.3125 , 0.15625, 0.03125])
np.sum(f)
0.9999999999999999
plt.scatter(x, f)

# https://roualdes.us/lecturenotes/binomial
# Q2
# a.
X = Binomial(10, 0.95)
fx = X.pmf(10)
fx
0.5987369392383787
# b.
np.sum(X.pmf(np.array([8, 9, 10])))
0.9884964426207032
s = np.arange(11)
plt.scatter(s, X.pmf(s))