SciPy

scipy.special.gammasgn

scipy.special.gammasgn(x) = <ufunc 'gammasgn'>

Sign of the gamma function.

It is defined as

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

where \(\Gamma\) is the Gamma function; see gamma. This definition is complete since the Gamma function is never zero; see the discussion after [dlmf].

Parameters
xarray_like

Real argument

Returns
scalar or ndarray

Sign of the Gamma function

See also

gamma

the Gamma function

gammaln

log of the absolute value of the Gamma function

loggamma

analytic continuation of the log of the Gamma function

Notes

The Gamma function can be computed as gammasgn(x) * np.exp(gammaln(x)).

References

dlmf

NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/5.2#E1

Examples

>>> import scipy.special as sc

It is 1 for x > 0.

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

It alternates between -1 and 1 for negative integers.

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

It can be used to compute the Gamma function.

>>> 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 ])

Previous topic

scipy.special.loggamma

Next topic

scipy.special.gammainc