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学习笔记之For循环用法详解

本文实例讲述了Python学习笔记之For循环用法。分享给大家供大家参考,具体如下: Python 中的For循环 Python 有两种类型的循环:for 循环和 while 循环。fo...

python在每个字符后添加空格的实例

实例如下所示: #!/usr/bin/env Python # coding=utf-8 file = open("chinese1.txt",'r') file2 = open(r...

Python中asyncio模块的深入讲解

1. 概述 Python中 asyncio 模块内置了对异步IO的支持,用于处理异步IO;是Python 3.4版本引入的标准库。 asyncio 的编程模型就是一个消息循环。我们从...

介绍Python中的fabs()方法的使用

 方法fabs()返回 x 的绝对值。 语法 以下是fabs()方法的语法: import math math.fabs( x ) 注意:此函数是无法直接访问的,所...

Python简单实现自动删除目录下空文件夹的方法

本文实例讲述了Python简单实现自动删除目录下空文件夹的方法。分享给大家供大家参考,具体如下: 总是发现电脑用上一段时间,各种软件生成各种目录,可是这些目录都是空文件夹,感觉没用,或许...