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动态加载变量示例分享

众所周知,程序在启动后,各个程序文件都会被加载到内存中,这样如果程序文本再次变化,对当前程序的运行没有影响,这对程序是一种保护。 但是,对于像python这样解释执行的语言,我们有时候会...

在arcgis使用python脚本进行字段计算时是如何解决中文问题的

在arcgis使用python脚本进行字段计算时是如何解决中文问题的

一、引言   在arcgis打开一个图层的属性表,可以对属性表的某个字段进行计算,但是在平常一般都是使用arcgis提供的字段计算器的界面进行傻瓜式的简答的赋值操作,并没有使用到脚本对字...

python实现批量文件重命名

python实现批量文件重命名

本文实例为大家分享了python批量文件重命名的具体代码,供大家参考,具体内容如下 问题描述 最近遇到朋友求助,如何将大量文件名前面的某些字符删除。 即将图中文件前的编号删除。 P...

使用PyTorch将文件夹下的图片分为训练集和验证集实例

PyTorch提供了ImageFolder的类来加载文件结构如下的图片数据集: root/dog/xxx.png root/dog/xxy.png root/dog/xxz.png...

Python连接Mssql基础教程之Python库pymssql

前言 pymssql模块是用于sql server数据库(一种数据库通用接口标准)的连接。另外pyodbc不仅限于SQL server,还包括Oracle,MySQL,Access,Ex...