scipy.special.gammasgn#

scipy.special.gammasgn(x, out=None) = <ufunc 'gammasgn'>#

伽瑪函數的符號。

其定義為

\[\begin{split}\text{gammasgn}(x) = \begin{cases} +1 & \Gamma(x) > 0 \\ -1 & \Gamma(x) < 0 \end{cases}\end{split}\]

其中 \(\Gamma\) 是伽瑪函數;參見 gamma。此定義是完整的,因為伽瑪函數永遠不為零;參見 [dlmf] 後的討論。

參數:
xarray_like

實數引數

outndarray,選用

函數值的選用輸出陣列

返回:
純量或 ndarray

伽瑪函數的符號

另請參閱

gamma

伽瑪函數

gammaln

伽瑪函數絕對值的對數

loggamma

伽瑪函數對數的解析延拓

註解

伽瑪函數可以計算為 gammasgn(x) * np.exp(gammaln(x))

參考文獻

[dlmf]

NIST 數位數學函數庫 https://dlmf.nist.gov/5.2#E1

範例

>>> import numpy as np
>>> import scipy.special as sc

x > 0 時為 1。

>>> sc.gammasgn([1, 2, 3, 4])
array([1., 1., 1., 1.])

對於負整數,它在 -1 和 1 之間交替。

>>> sc.gammasgn([-0.5, -1.5, -2.5, -3.5])
array([-1.,  1., -1.,  1.])

它可以用於計算伽瑪函數。

>>> x = [1.5, 0.5, -0.5, -1.5]
>>> sc.gammasgn(x) * np.exp(sc.gammaln(x))
array([ 0.88622693,  1.77245385, -3.5449077 ,  2.3632718 ])
>>> sc.gamma(x)
array([ 0.88622693,  1.77245385, -3.5449077 ,  2.3632718 ])