CS计算机代考程序代写 In [1]:

In [1]:
import matplotlib.pyplot as plt
import scipy.special as spsp
import numpy as np
%matplotlib inline
In [9]:
n=6
p=0.2
outcome=np.arange(n+1)
probs=spsp.factorial(n)/spsp.factorial(outcome)/spsp.factorial(n-outcome)
probs=probs*outcome*(1-p)**(n-outcome)

cdf=np.cumsum(probs)
def discrete_sample():
u=np.random.rand()
for i in range(len(cdf)):
if u