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模拟用户登录验证

本文实例为大家分享了Python模拟用户登录验证的具体代码,供大家参考,具体内容如下 1.功能简介 此程序模拟用户登录验证的过程,实现用户名输入、黑名单检测、用户有效性判别、密码输入及验...

python图像常规操作

python图像常规操作

使用python进行基本的图像操作与处理 前言: 与早期计算机视觉领域多数程序都是由 C/C++ 写就的情形不同。随着计算机硬件速度越来越快,研究者在考虑选择实现算法语言的时候会更多地考...

Python实现二分法算法实例

1.算法:(设查找的数组期间为array[low, high]) (1)确定该期间的中间位置K (2)将查找的值T与array[k]比较。若相等,查找成功返回此位置;否则确定新的查找区域...

在python中实现强制关闭线程的示例

如下所示: import threading import time import inspect import ctypes def _async_raise(tid, exc...

python小项目之五子棋游戏

python小项目之五子棋游戏

本文实例为大家分享了python五子棋游戏的具体代码,供大家参考,具体内容如下 1.项目简介 在刚刚学习完python套接字的时候做的一个五子棋小游戏,可以在局域网内双人对战,也可以和电...