添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
好帅的香菜  ·  在RHEL / CentOS ...·  2 年前    · 
火星上的油条  ·  Spring ...·  2 年前    · 
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> list_a = np.random.binomial(n=10,p=0.2,size=1000)
#取样1000次,每次进行十组试验,单组试验成功概率为0.2,list_a为每组试验中成功的组数
>>> plt.hist(list_a,bins=8,color='g',alpha=0.4,edgecolor='b')
(array([ 157.,  240.,  236.,  208.,   86.,   57.,   13.,    3.]), array([ 0.   ,  1.125,  2.25 ,  3.375,  4.5  ,  5.625,  6.75 ,  7.875,  9.   ]), <a list of 8 Patch objects>)
>>> plt.show()

设一个某站台平均每小时会经过8辆公共汽车,求每小时经过12俩的概率:

>>> list_b = np.random.poisson(8,1000)#试验重复1000次
>>> plt.hist(list_b,bins=8,color='g',alpha=0.4,edgecolor='b')
(array([  14.,   71.,  201.,  269.,  236.,  132.,   60.,   17.]), array([  1.,   3.,   5.,   7.,   9.,  11.,  13.,  15.,  17.]), <a list of 8 Patch objects>)
>>> plt.show()
>>> list_c = np.random.uniform(0,10,1000)
>>> plt.hist(list_c,bins=8,color='g',alpha=0.4,edgecolor='b')
(array([ 141.,  123.,  111.,  111.,  131.,  137.,  125.,  121.]), array([  4.09722532e-03,   1.25088530e+00,   2.49767338e+00,
         3.74446146e+00,   4.99124954e+00,   6.23803761e+00,
         7.48482569e+00,   8.73161377e+00,   9.97840185e+00]), <a list of 8 Patch objects>)
>>> plt.show()

当二项分布的样本数量足够大时,其分布曲线会变成对称的钟形,我们将这种分布形态成为正态分布

Python实现及图像

list_d = np.random(loc,scale,size=None)
#loc为期望
#scale为标准差
#size为取样数量,默认为None,即仅返回一个数
>>> list_d = np.random.normal(0,1,1000)
>>> plt.hist(list_d,bins=8,color='g',alpha=0.4,edgecolor='b')
(array([  11.,   53.,  158.,  321.,  264.,  145.,   39.,    9.]), array([-3.34109196, -2.50103319, -1.66097443, -0.82091566,  0.0191431 ,
        0.85920186,  1.69926063,  2.53931939,  3.37937815]), <a list of 8 Patch objects>)
>>> plt.show()

指数分布与泊松分布类似,泊松分布描述了每一个区间内事件发生的次数,而指数分布描述了事件发生的事件间隔长度。
设一个某站台平均每小时会经过8辆公共汽车,求两辆公共汽车间隔时间不超过x小时的概率:

Python实现即图像

>>> list_e = np.random.exponential(0.125,1000)
>>> plt.hist(list_e,bins=8,color='g',edgecolor='b',alpha=0.4)
(array([ 552.,  250.,  121.,   49.,   15.,    6.,    4.,    3.]), array([  1.38250181e-04,   1.06106465e-01,   2.12074680e-01,
         3.18042896e-01,   4.24011111e-01,   5.29979326e-01,
         6.35947541e-01,   7.41915756e-01,   8.47883971e-01]), <a list of 8 Patch objects>)
>>> plt.show()