本文簡要介紹 python 語言中 numpy.random.RandomState.noncentral_chisquare
的用法。
用法:
random.RandomState.noncentral_chisquare(df, nonc, size=None)
從非中心卡方分布中抽取樣本。
非中心 分布是 分布的泛化。
注意
新代碼應改為使用
default_rng()
實例的noncentral_chisquare
方法;請參閱快速入門。- df: 浮點數或類似數組的浮點數
自由度,必須 > 0。
- nonc: 浮點數或類似數組的浮點數
非中心性,必須是非負的。
- size: int 或整數元組,可選
輸出形狀。例如,如果給定的形狀是
(m, n, k)
,則繪製m * n * k
樣本。如果 size 為None
(默認),如果df
和nonc
都是標量,則返回單個值。否則,將抽取np.broadcast(df, nonc).size
樣本。
- out: ndarray 或標量
從參數化的非中心卡方分布中抽取樣本。
參數:
返回:
注意:
非中心卡方分布的概率密度函數為
其中 是自由度為 q 的卡方。
參考:
維基百科,“非中心卡方分布”https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution
1:
例子:
從分布中繪製值並繪製直方圖
>>> import matplotlib.pyplot as plt >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000), ... bins=200, density=True) >>> plt.show()
從具有非常小的非中心性的非中心卡方中提取值,並與卡方進行比較。
>>> plt.figure() >>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000), ... bins=np.arange(0., 25, .1), density=True) >>> values2 = plt.hist(np.random.chisquare(3, 100000), ... bins=np.arange(0., 25, .1), density=True) >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob') >>> plt.show()
證明非中心性的大值如何導致更對稱的分布。
>>> plt.figure() >>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000), ... bins=200, density=True) >>> plt.show()
相關用法
- Python numpy RandomState.noncentral_f用法及代碼示例
- Python numpy RandomState.normal用法及代碼示例
- Python numpy RandomState.negative_binomial用法及代碼示例
- Python numpy RandomState.standard_exponential用法及代碼示例
- Python numpy RandomState.bytes用法及代碼示例
- Python numpy RandomState.uniform用法及代碼示例
- Python numpy RandomState.standard_gamma用法及代碼示例
- Python numpy RandomState.seed用法及代碼示例
- Python numpy RandomState.power用法及代碼示例
- Python numpy RandomState.standard_normal用法及代碼示例
- Python numpy RandomState.geometric用法及代碼示例
- Python numpy RandomState.random_sample用法及代碼示例
- Python numpy RandomState.gumbel用法及代碼示例
- Python numpy RandomState.logseries用法及代碼示例
- Python numpy RandomState.wald用法及代碼示例
- Python numpy RandomState.chisquare用法及代碼示例
- Python numpy RandomState.poisson用法及代碼示例
- Python numpy RandomState.randn用法及代碼示例
- Python numpy RandomState.vonmises用法及代碼示例
- Python numpy RandomState.gamma用法及代碼示例
- Python numpy RandomState.zipf用法及代碼示例
- Python numpy RandomState.triangular用法及代碼示例
- Python numpy RandomState.f用法及代碼示例
- Python numpy RandomState.shuffle用法及代碼示例
- Python numpy RandomState.rayleigh用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.random.RandomState.noncentral_chisquare。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。