python-numpy-指数分布实例详解

yipeiwu_com5年前Python基础

如下所示:

# Seed random number generator
np.random.seed(42)
 
# Compute mean no-hitter time: tau
tau = np.mean(nohitter_times)
 
# Draw out of an exponential distribution with parameter tau: inter_nohitter_time
inter_nohitter_time = np.random.exponential(tau, 100000)
 
# Plot the PDF and label axes
_ = plt.hist(inter_nohitter_time,
    bins=50, normed=True, histtype='step')
_ = plt.xlabel('Games between no-hitters')
_ = plt.ylabel('PDF')
 
# Show the plot
plt.show()

指数分布的拟合

# Create an ECDF from real data: x, y
x, y = ecdf(nohitter_times)
 
# Create a CDF from theoretical samples: x_theor, y_theor
x_theor, y_theor = ecdf(inter_nohitter_time)
 
# Overlay the plots
plt.plot(x_theor, y_theor)
plt.plot(x, y, marker='.', linestyle='none')
 
# Margins and axis labels
plt.margins(0.02)
plt.xlabel('Games between no-hitters')
plt.ylabel('CDF')
 
# Show the plot
plt.show()

以上这篇python-numpy-指数分布实例详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

两个命令把 Vim 打造成 Python IDE的方法

两个命令把 Vim 打造成 Python IDE的方法

运行下面两个命令,即可把 Vim(含插件)配置成 Python IDE。目前支持 MAC 和 Ubuntu。 curl -O https://raw.githubuserconten...

Python3中常用的处理时间和实现定时任务的方法的介绍

无论哪种编程语言,时间肯定都是非常重要的部分,今天来看一下python如何来处理时间和python定时任务,注意咯:本篇所讲是python3版本的实现,在python2版本中的实现略有不...

与Django结合利用模型对上传图片预测的实例详解

1 预处理 (1)对上传的图片进行预处理成100*100大小 def prepicture(picname): img = Image.open('./media/pic/' +...

对pandas replace函数的使用方法小结

对pandas replace函数的使用方法小结

语法:replace(self, to_replace=None, value=None, inplace=False, limit=None, regex=False, method=...

python networkx 根据图的权重画图实现

python networkx 根据图的权重画图实现

首先输入边和边的权重,随后画出节点位置,根据权重大小划分实边和虚边 #coding:utf-8 #!/usr/bin/env python """ An example using...