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设计】。

相关文章

在Python中处理XML的教程

XML虽然比JSON复杂,在Web中应用也不如以前多了,不过仍有很多地方在用,所以,有必要了解如何操作XML。 DOM vs SAX 操作XML有两种方法:DOM和SAX。DOM会把整个...

django框架中间件原理与用法详解

django框架中间件原理与用法详解

本文实例讲述了django框架中间件原理与用法。分享给大家供大家参考,具体如下: 中间件:轻量级,介于 request和response之间的一道处理过程,在全局上改变了输入和输出 在d...

python增加图像对比度的方法

本代码实现的是,在旋转10度的基础上,再进行增加对比度的操作。 1 代码: 代码注释中的代码都是可以运行的.  但是不怎么靠谱,因为文件名被逐个编辑,有可能与原标签不对应,,更...

python创建文件备份的脚本

制作文件备份 打开原文件 old_f_name = input(“请输入备份的文件路径:”) old_f = open(old_f_name, “r”) 打开新文件...

python fabric实现远程操作和部署示例

近期接手越来越多的东西,发布和运维的工作相当机械,加上频率还蛮高,导致时间浪费还是优点多。修复bug什么的,测试,提交版本库(2分钟),ssh到测试环境pull部署(2分钟),rsync...