numpy.random.RandomState.rayleigh#
方法
- random.RandomState.rayleigh(scale=1.0, size=None)#
從 Rayleigh 分佈中抽取樣本。
\(\chi\) 和 Weibull 分佈是 Rayleigh 的推廣。
- 參數:
- scalefloat 或 float 的類陣列, 選項性
尺度,也等於眾數。必須是非負數。預設值為 1。
- sizeint 或 int 的 tuple, 選項性
輸出形狀。如果給定的形狀是,例如,
(m, n, k)
,則會抽取m * n * k
個樣本。如果 size 是None
(預設值),則當scale
是純量時,會傳回單一值。否則,會抽取np.array(scale).size
個樣本。
- 回傳值:
- outndarray 或 純量
從參數化的 Rayleigh 分佈中抽取的樣本。
另請參閱
random.Generator.rayleigh
新程式碼應使用此方法。
註解
Rayleigh 分佈的機率密度函數為
\[P(x;scale) = \frac{x}{scale^2}e^{\frac{-x^2}{2 \cdotp scale^2}}\]例如,如果風速的東向和北向分量具有相同的零均值高斯分佈,則會出現 Rayleigh 分佈。那麼風速將具有 Rayleigh 分佈。
參考文獻
[1]Brighton Webs Ltd., “Rayleigh Distribution,” https://web.archive.org/web/20090514091424/http://brighton-webs.co.uk:80/distributions/rayleigh.asp
[2]Wikipedia, “Rayleigh distribution” https://en.wikipedia.org/wiki/Rayleigh_distribution
範例
從分佈中抽取值並繪製直方圖
>>> from matplotlib.pyplot import hist >>> values = hist(np.random.rayleigh(3, 100000), bins=200, density=True)
波浪高度往往遵循 Rayleigh 分佈。如果平均波高為 1 公尺,則可能有多少比例的波浪會大於 3 公尺?
>>> meanvalue = 1 >>> modevalue = np.sqrt(2 / np.pi) * meanvalue >>> s = np.random.rayleigh(modevalue, 1000000)
大於 3 公尺的波浪百分比為
>>> 100.*sum(s>3)/1000000. 0.087300000000000003 # random