scipy.special.gammaln#
- scipy.special.gammaln(x, out=None) = <ufunc 'gammaln'>#
伽瑪函數絕對值的對數。
定義為
\[\ln(\lvert\Gamma(x)\rvert)\]其中 \(\Gamma\) 是伽瑪函數。 有關伽瑪函數的更多詳細資訊,請參閱 [dlmf]。
- 參數:
- xarray_like
實數引數
- outndarray, optional
函數結果的可選輸出陣列
- 回傳值:
- 純量或 ndarray
伽瑪函數絕對值的對數值
筆記
它與 Python 標準函式庫函式
math.lgamma
是相同的函數。當與
gammasgn
結合使用時,此函數可用於在實軸上的對數空間中工作,而無需透過關係式exp(gammaln(x)) = gammasgn(x) * gamma(x)
處理複數。對於複數值對數伽瑪函數,請使用
loggamma
而不是gammaln
。參考文獻
[dlmf]NIST 數位數學函數庫 https://dlmf.nist.gov/5
範例
>>> import numpy as np >>> import scipy.special as sc
它有兩個正零點。
>>> sc.gammaln([1, 2]) array([0., 0.])
它在非正整數處有極點。
>>> sc.gammaln([0, -1, -2, -3, -4]) array([inf, inf, inf, inf, inf])
它漸近地逼近
x * log(x)
(斯特靈公式)。>>> x = np.array([1e10, 1e20, 1e40, 1e80]) >>> sc.gammaln(x) array([2.20258509e+11, 4.50517019e+21, 9.11034037e+41, 1.83206807e+82]) >>> x * np.log(x) array([2.30258509e+11, 4.60517019e+21, 9.21034037e+41, 1.84206807e+82])