借助於numpy.random.triangular()方法,我們可以從區間[left,right]的三角形分布中獲取隨機樣本,並使用此方法返回隨機樣本。
用法:numpy.random.triangular(left, mode, right, size=None)
參數:
1)左-三角形的下限。
2)模式-峰值分布。
3)右-三角形的上限。
4)大小-所需樣本總數。
Return:以numpy數組形式返回隨機樣本。
範例1:
在此示例中,我們可以看到,通過使用numpy.random.triangular()方法,我們能夠獲取三角形分布的隨機樣本並返回numpy數組。
Python3
# import numpy
import numpy as np
import matplotlib.pyplot as plt
# Using triangular() method
gfg = np.random.triangular(-5, 0, 5, 5000)
plt.hist(gfg, bins = 50, density = True)
plt.show()
輸出:
範例2:
Python3
# import numpy
import numpy as np
import matplotlib.pyplot as plt
# Using triangular() method
gfg = np.random.triangular(-10, 8, 10, 15000)
plt.hist(gfg, bins = 100, density = True)
plt.show()
輸出:
相關用法
- Python numpy.std()用法及代碼示例
- Python numpy.mean()用法及代碼示例
- Python numpy.irr()用法及代碼示例
- Python numpy.lcm()用法及代碼示例
- Python numpy.gcd()用法及代碼示例
- Python numpy.pmt()用法及代碼示例
- Python numpy.sum()用法及代碼示例
- Python numpy.inner()用法及代碼示例
- Python numpy.var()用法及代碼示例
- Python numpy.around()用法及代碼示例
- Python numpy.tan()用法及代碼示例
- Python numpy.cos()用法及代碼示例
- Python numpy.sin()用法及代碼示例
- Python numpy.mod()用法及代碼示例
- Python numpy.exp()用法及代碼示例
- Python numpy.log()用法及代碼示例
- Python numpy.fix()用法及代碼示例
- Python numpy.pv()用法及代碼示例
- Python numpy.fv()用法及代碼示例
- Python numpy.npv()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 numpy.random.triangular() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。