本文簡要介紹 python 語言中 scipy.special.agm
的用法。
用法:
scipy.special.agm(a, b, out=None) = <ufunc 'agm'>#
計算 a 和 b 的 arithmetic-geometric 平均值。
從 a_0 = a 和 b_0 = b 開始並迭代計算:
a_{n+1} = (a_n + b_n)/2 b_{n+1} = sqrt(a_n*b_n)
a_n 和 b_n 隨著 n 的增加收斂到相同的極限;它們的共同極限是 agm(a, b)。
- a, b: array_like
僅實際值。如果兩個值都為負,則結果為負。如果一個值為負而另一個為正,則返回 nan。
- out: ndarray,可選
函數值的可選輸出數組
- 標量或 ndarray
a 和 b 的 arithmetic-geometric 平均值。
參數 ::
返回 ::
例子:
>>> import numpy as np >>> from scipy.special import agm >>> a, b = 24.0, 6.0 >>> agm(a, b) 13.458171481725614
將該結果與迭代進行比較:
>>> while a != b: ... a, b = (a + b)/2, np.sqrt(a*b) ... print("a = %19.16f b=%19.16f" % (a, b)) ... a = 15.0000000000000000 b=12.0000000000000000 a = 13.5000000000000000 b=13.4164078649987388 a = 13.4582039324993694 b=13.4581390309909850 a = 13.4581714817451772 b=13.4581714817060547 a = 13.4581714817256159 b=13.4581714817256159
當給出類似數組的參數時,廣播適用:
>>> a = np.array([[1.5], [3], [6]]) # a has shape (3, 1). >>> b = np.array([6, 12, 24, 48]) # b has shape (4,). >>> agm(a, b) array([[ 3.36454287, 5.42363427, 9.05798751, 15.53650756], [ 4.37037309, 6.72908574, 10.84726853, 18.11597502], [ 6. , 8.74074619, 13.45817148, 21.69453707]])
相關用法
- Python SciPy special.airy用法及代碼示例
- Python SciPy special.airye用法及代碼示例
- Python SciPy special.ai_zeros用法及代碼示例
- Python SciPy special.exp1用法及代碼示例
- Python SciPy special.expn用法及代碼示例
- Python SciPy special.ncfdtri用法及代碼示例
- Python SciPy special.gamma用法及代碼示例
- Python SciPy special.y1用法及代碼示例
- Python SciPy special.y0用法及代碼示例
- Python SciPy special.ellip_harm_2用法及代碼示例
- Python SciPy special.i1e用法及代碼示例
- Python SciPy special.smirnovi用法及代碼示例
- Python SciPy special.ker用法及代碼示例
- Python SciPy special.ynp_zeros用法及代碼示例
- Python SciPy special.k0e用法及代碼示例
- Python SciPy special.j1用法及代碼示例
- Python SciPy special.logsumexp用法及代碼示例
- Python SciPy special.expit用法及代碼示例
- Python SciPy special.polygamma用法及代碼示例
- Python SciPy special.nbdtrik用法及代碼示例
- Python SciPy special.nbdtrin用法及代碼示例
- Python SciPy special.seterr用法及代碼示例
- Python SciPy special.ncfdtr用法及代碼示例
- Python SciPy special.pdtr用法及代碼示例
- Python SciPy special.expm1用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.special.agm。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。