scipy.special.gammasgn#
- scipy.special.gammasgn(x, out=None) = <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
- outndarray, optional
Optional output array for the function values
- Returns:
- scalar or ndarray
Sign of the gamma function
See also
Notes
The gamma function can be computed as
gammasgn(x) * np.exp(gammaln(x)).Array API Standard Support
gammasgnhas support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
⛔
JAX
✅
✅
Dask
✅
n/a
For the NumPy backend, this function supports all NumPy ufunc keyword arguments. Other backends may support
out, but none of the other ufunc kwargs.outis typically supported for CuPy and PyTorch, but not currently in cases where SciPy relies on a generic Array API implementation or, for PyTorch on CPU, falls back to the NumPy backend.outis never supported for JAX because JAX arrays are immutable.gammasgndoes not currently supportoutfor the PyTorch backend.See Support for the array API standard for more information.
References
[dlmf]NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/5.2#E1
Examples
>>> import numpy as np >>> 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 half-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 ])