當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy.random.rayleigh()用法及代碼示例

借助numpy.random.rayleigh()方法,我們可以從瑞利分布中獲取隨機樣本並返回隨機樣本。

瑞利分布函數

用法:numpy.random.rayleigh(scale=1.0, size=None)

Return:以numpy數組形式返回隨機樣本。

範例1:

在此示例中,我們可以看到,通過使用numpy.random.rayleigh()方法,我們可以獲得瑞利分布並返回隨機樣本。



Python3

# import numpy 
import numpy as np 
import matplotlib.pyplot as plt 
  
# Using rayleigh() method 
gfg = np.random.rayleigh(3.4, 50000) 
  
plt.figure() 
plt.hist(gfg, bins = 50, density = True) 
plt.show()

輸出:

範例2:

Python3

# import numpy 
import numpy as np 
import matplotlib.pyplot as plt 
  
# Using rayleigh() method 
gfg = np.random.rayleigh(2 * np.sqrt(np.pi), 100000) 
  
plt.figure() 
plt.hist(gfg, bins = 50, density = True) 
plt.show()

輸出:

相關用法


注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 numpy.random.rayleigh() in python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。