import matplotlib.pyplot as plt
import numpy as np
课程要求画图,查看官方文档
numpy.random.binomial(n, p, size=None)
n trials and p probability of success where n an integer >= 0 and p is in the interval [0,1].
size这里为模拟的次数
n = 10
p = .5
s = np.random.binomial(n, p, size=100000)
plt.xlabel("n=10, p=0.5")
plt.ylabel("Binomial")
count, bins, ignored = plt.hist(s, 10, color="blue", normed=True)
plt.show()
size越大越接近理想模型
np.random.poisson(lam=1.0, size=None)
同上
s = np.random.poisson(lam=3, size=200000)
plt.xlabel("lambda=3")
plt.ylabel("Poisson")
count, bins, ignored = plt.hist(s, 14, color="yellow", normed=True)
plt.show()