# 二項分布

``````>>> from pylab import *
>>> from scipy.stats import *
>>> [ n, p ] = [10, 0.3]
>>> x = scipy.linspace(0,10,11)
>>> pmf = binom.pmf(x,n,p)
>>> plot(x,pmf)
[<matplotlib.lines.Line2D object at 0x0440C290>]
'\n\nPoisson distribution\n\npoisson.pmf(k, mu) = exp(-mu) * mu**k / k!\nfor k >= 0\n'
>>>```
```
``````>>> from scipy.stats import binom
>>> [ n, p ] = [10, 0.3]
>>> brv = binom(n, p)
>>> x = np.arange(0, np.minimum(brv.dist.b, 3))
>>> h = plt.vlines(x, 0, brv.pmf(x), lw=2)
>>> prb = binom.cdf(x, n, p)
>>> h = plt.semilogy(np.abs(x - binom.ppf(prb, n, p)) + 1e-20)
>>> R = binom.rvs(n, p, size=100)
>>> R
array([4, 1, 3, 0, 3, 5, 3, 3, 3, 4, 3, 5, 1, 4, 6, 8, 1, 4, 3, 7, 2, 2, 3,
1, 4, 5, 1, 4, 3, 3, 5, 5, 3, 3, 3, 3, 1, 2, 3, 2, 3, 4, 3, 3, 1, 1,
5, 3, 3, 2, 6, 3, 8, 3, 3, 1, 2, 4, 2, 0, 4, 1, 1, 3, 5, 6, 4, 3, 3,
3, 4, 4, 3, 2, 3, 2, 1, 9, 3, 4, 0, 1, 3, 3, 4, 3, 5, 3, 3, 3, 1, 5,
2, 2, 0, 2, 3, 1, 4, 4])
>>> import scipy, scipy.stats
>>> x = scipy.linspace(0,10,11)
>>> pmf = scipy.stats.binom.pmf(x,10,0.3)
>>> import pylab
>>> pylab.plot(x,pmf)

>>> from scipy.stats import *
'\n\nPoisson distribution\n\npoisson.pmf(k, mu) = exp(-mu) * mu**k / k!\nfor k >= 0\n'```
```

# 常態分布

``````>>> import numpy.random
>>> normal(5,2,100)
array([ 3.21471036,  5.26492657,  7.70783675,  2.45057301,  3.38467506,
6.02133021,  5.54276479,  3.26465946,  8.25837716,  4.39272658,
1.24767395,  4.33467667,  3.6443019 ,  6.49579066,  6.86866816,
4.59111526,  3.51287367,  2.56129962,  4.81363112,  2.63946308,
4.9807356 ,  1.85818983,  6.15656543,  8.27378843,  3.83604829,
5.33750668,  4.96560262,  3.52112677,  3.2764357 ,  2.60515476,
5.21304892,  5.61690169,  7.50435424,  6.0863938 ,  7.7009313 ,
3.65751577,  3.62680564,  2.63720339,  6.21006112,  6.35392547,
8.22454502,  5.41087811,  7.68067589,  9.06213807,  1.40528522,
5.29779808,  5.42503552,  6.05408346,  2.76095598,  8.9789405 ,
6.54901084,  3.51942225,  3.25304462,  7.55555912,  2.53087829,
5.24182882,  2.8376421 ,  4.93349075,  4.28160442,  4.23970118,
5.41912371,  3.42975451,  4.4068796 ,  5.81515187,  5.84498129,
4.07861343,  1.8709632 ,  5.42019151,  4.84400278,  3.65720382,
6.69450148,  5.06283132,  5.70210134,  5.64788014,  7.04476919,
2.74535951,  5.2997555 ,  7.46769138,  2.08309793,  5.24436093,
3.9783337 ,  4.49827403,  3.93028157,  6.73267554,  4.72471469,
3.25538104,  5.74261214,  3.11882094,  3.46840247,  6.17753036,
1.6790931 ,  5.95095584,  7.52904972,  7.69310604,  4.20202791,
6.36995648,  2.48046827,  8.39468623,  5.16113417,  8.90246688])```
```