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 词典(Dict) 加载与保存示例

Dict的加载: import json def load_dict(filename): '''load dict from json file''' with open(f...

python采集微信公众号文章

python采集微信公众号文章

本文实例为大家分享了python采集微信公众号文章的具体代码,供大家参考,具体内容如下 在python一个子目录里存2个文件,分别是:采集公众号文章.py和config.py。 代码如下...

python 将dicom图片转换成jpg图片的实例

主要原理:调整dicom的窗宽,使之各个像素点上的灰度值缩放至[0,255]范围内。 使用到的python库:SimpleITK 下面是一个将dicom(.dcm)图片转换成jpg图片的...

PyTorch学习:动态图和静态图的例子

动态图和静态图 目前神经网络框架分为静态图框架和动态图框架,PyTorch 和 TensorFlow、Caffe 等框架最大的区别就是他们拥有不同的计算图表现形式。 TensorFlow...

详解python中自定义超时异常的几种方法

最近在项目中调用第三方接口时候,经常会出现请求超时的情况,或者参数的问题导致调用异代码异常。针对超时异常,查询了python 相关文档,没有并发现完善的包来根据用户自定义的时间来抛出超时...