【发布时间】:2017-09-10 21:47:46
【问题描述】:
我对所有不同的分布函数(即 numpy、scipy、matploglib.mlab 和 random)有点困惑
我正在尝试获取伽玛分布数的样本以用于我的程序,并绘制出正在使用的分布。
到目前为止,我正在做:
import random
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import scipy.special as sps
import numpy as np
k = 2.0
theta = 2.0
random.gammavariate(k, theta) # this gives me results of the gamma distribution
# but unfortunately, this doesn't work
# plt.plot(random.gammavariate(k, theta))
# plt.show()
# but this works somehow even if I don't specify
# what bins and y is - just copied from a https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.gamma.html
# and seems to work
s = np.random.gamma(k, theta, 1000)
plt.plot(bins, y, linewidth=2, color='r')
非常感谢您向我解释这一点的任何帮助。
【问题讨论】:
-
"...并且还绘制出正在使用的分布。" 您是要绘制随机样本的直方图,还是要绘制抽取样本的基础分布的 PDF(或 CDF)(例如 en.wikipedia.org/wiki/Gamma_distribution 处显示的图)?
标签: numpy matplotlib scipy distribution