numpy.random.rayleigh#

random.rayleigh(scale=1.0, size=None)#

從 Rayleigh 分佈中抽取樣本。

\(\chi\) 分佈和 Weibull 分佈是 Rayleigh 分佈的推廣。

注意

新程式碼應改用 rayleigh 方法,該方法屬於 Generator 實例;請參閱快速入門

參數:
scalefloat 或 float 的類陣列物件,選填

尺度,也等於眾數。必須是非負數。預設值為 1。

sizeint 或 int 元組,選填

輸出形狀。如果給定的形狀是,例如 (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 分佈。

參考文獻

範例

從分佈中抽取值並繪製直方圖

>>> 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