numpy.random.rayleigh#

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

从瑞利分布中抽取样本.

\(\chi\) 和 Weibull 分布是瑞利分布的推广.

备注

新代码应该使用 rayleigh 方法,该方法存在于 Generator 实例中;请参考 快速入门 .

参数:
scalefloat 或 float 的类数组,可选

尺度,也等于众数.必须是非负的.默认为 1.

sizeint 或 int 的元组,可选.

输出形状.如果给定的形状是,例如, (m, n, k) ,则抽取 m * n * k 个样本.如果 size 为 None (默认值),则如果 scale 是标量,则返回单个值.否则,抽取 np.array(scale).size 个样本.

返回:
outndarray 或标量

从参数化的瑞利分布中抽取的样本.

参见

random.Generator.rayleigh

新代码应该使用这个.

注释

瑞利分布的概率密度函数为

\[P(x;scale) = \frac{x}{scale^2}e^{\frac{-x^2}{2 \cdotp scale^2}}\]

例如,如果风速的东向和北向分量具有相同的零均值高斯分布,则会Ob出现瑞利分布. 然后,风速将具有瑞利分布.

参考

示例

从分布中抽取值并绘制直方图

>>> from matplotlib.pyplot import hist
>>> values = hist(np.random.rayleigh(3, 100000), bins=200, density=True)

浪高往往服从瑞利分布.如果平均浪高为 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