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实现自动重启本程序的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/local/bin/python #-*- coding: UTF-8 -...

Python面向对象之多态原理与用法案例分析

Python面向对象之多态原理与用法案例分析

本文实例讲述了Python面向对象之多态原理与用法。分享给大家供大家参考,具体如下: 目标 多态 面向对象三大特性 封装 根据 职责 将 属性 和 方法 封装 到一个抽象的 类 中 定义...

Python求解任意闭区间的所有素数

题目:请求出任意区间[a,b]的所有素数,简单考虑实用性 这道题看起来应该很easy是吧,但任意区间(这个问题有没get 到) Afanty的分析: 1、首先明白什么叫素数,注意用求余法...

python超简单解决约瑟夫环问题

本文实例讲述了python超简单解决约瑟夫环问题的方法。分享给大家供大家参考。具体分析如下: 约瑟环问题大家都熟悉。题目是这样的。一共有三十个人,从1-30依次编号。每次隔9个人就踢出去...

python基于itchat模块实现微信防撤回

有时候,女神发来一条消息,说约你看电影,她考虑了一下,又撤回了,不约你了…而你又想知道她究竟发了什么,该怎么办?微信防撤回了解一下。 环境要求 Python3 电脑 安装itcha...