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实现Windows上气泡提醒效果的方法

本文实例讲述了Python实现Windows上气泡提醒效果的方法。分享给大家供大家参考。具体实现方法如下: # -*- encoding: gbk -*- import sys...

基于python及pytorch中乘法的使用详解

numpy中的乘法 A = np.array([[1, 2, 3], [2, 3, 4]]) B = np.array([[1, 0, 1], [2, 1, -1]]) C = np...

python 把列表转化为字符串的方法

列表转化为字符串 如下所示: >>> list1=['ak','uk',4] >>> list2=[str(i) for i in list1]...

Python中optionParser模块的使用方法实例教程

本文以实例形式较为详尽的讲述了Python中optionParser模块的使用方法,对于深入学习Python有很好的借鉴价值。分享给大家供大家参考之用。具体分析如下: 一般来说,Pyth...