本文簡要介紹 python 語言中 scipy.stats.variation
的用法。
用法:
scipy.stats.variation(a, axis=0, nan_policy='propagate', ddof=0, *, keepdims=False)#
計算變異係數。
變異係數是標準差除以平均值。這個函數等價於:
np.std(x, axis=axis, ddof=ddof) / np.mean(x)
ddof
的默認值為 0,但變異係數的許多定義使用無偏樣本方差的平方根作為樣本標準差,對應於ddof=1
。該函數不取數據均值的絕對值,因此如果均值為負,則返回值為負。
- a: array_like
輸入數組。
- axis: int 或無,可選
計算變異係數的軸。默認值為 0。如果沒有,則計算整個數組 a。
- nan_policy: {‘propagate’, ‘raise’, ‘omit’},可選
定義當輸入包含
nan
時如何處理。可以使用以下選項:‘propagate’: return
nan
‘raise’: raise an exception
‘omit’: perform the calculation with
nan
values omitted
默認值為‘propagate’。
- ddof: 整數,可選
給出計算標準偏差時使用的“Delta 自由度”。用於計算標準差的除數是
N - ddof
,其中N
是元素的數量。ddof必須小於N
;如果不是,結果將是nan
或者inf
, 根據N
和數組中的值。默認ddof為向後兼容為零,但建議使用ddof=1
以確保將樣本標準差計算為無偏樣本方差的平方根。- keepdims: 布爾型,可選
如果將其設置為 True,則縮小的軸將作為尺寸為 1 的尺寸留在結果中。使用此選項,結果將針對輸入數組正確廣播。
- variation: ndarray
沿請求軸計算的變化。
參數 ::
返回 ::
注意:
有幾種邊情況在不產生警告的情況下被處理:
如果均值和標準差均為零,則返回
nan
。如果均值為零且標準差不為零,則返回
inf
。如果輸入的長度為零(因為數組的長度為零,或者所有輸入值都是
nan
並且nan_policy
是'omit'
),則返回nan
。如果輸入包含
inf
,則返回nan
。
參考:
[1]Zwillinger, D. 和 Kokoska, S. (2000)。 CRC 標準概率和統計表和公式。查普曼和霍爾:紐約。 2000 年。
例子:
>>> import numpy as np >>> from scipy.stats import variation >>> variation([1, 2, 3, 4, 5], ddof=1) 0.5270462766947299
計算沿包含幾個
nan
值的數組的給定維度的變化:>>> x = np.array([[ 10.0, np.nan, 11.0, 19.0, 23.0, 29.0, 98.0], ... [ 29.0, 30.0, 32.0, 33.0, 35.0, 56.0, 57.0], ... [np.nan, np.nan, 12.0, 13.0, 16.0, 16.0, 17.0]]) >>> variation(x, axis=1, ddof=1, nan_policy='omit') array([1.05109361, 0.31428986, 0.146483 ])
相關用法
- Python SciPy stats.vonmises_line用法及代碼示例
- Python SciPy stats.vonmises_fisher用法及代碼示例
- Python SciPy stats.vonmises用法及代碼示例
- Python SciPy stats.anderson用法及代碼示例
- Python SciPy stats.iqr用法及代碼示例
- Python SciPy stats.genpareto用法及代碼示例
- Python SciPy stats.skewnorm用法及代碼示例
- Python SciPy stats.cosine用法及代碼示例
- Python SciPy stats.norminvgauss用法及代碼示例
- Python SciPy stats.directional_stats用法及代碼示例
- Python SciPy stats.invwishart用法及代碼示例
- Python SciPy stats.bartlett用法及代碼示例
- Python SciPy stats.levy_stable用法及代碼示例
- Python SciPy stats.page_trend_test用法及代碼示例
- Python SciPy stats.itemfreq用法及代碼示例
- Python SciPy stats.exponpow用法及代碼示例
- Python SciPy stats.gumbel_l用法及代碼示例
- Python SciPy stats.chisquare用法及代碼示例
- Python SciPy stats.semicircular用法及代碼示例
- Python SciPy stats.gzscore用法及代碼示例
- Python SciPy stats.gompertz用法及代碼示例
- Python SciPy stats.normaltest用法及代碼示例
- Python SciPy stats.dirichlet_multinomial用法及代碼示例
- Python SciPy stats.genlogistic用法及代碼示例
- Python SciPy stats.skellam用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.stats.variation。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。