scipy.special.log_gammainc#

scipy.special.log_gammainc(a, x, out=None) = <wrapped_ufunc 'log_gammainc'>#

Logarithm of the regularized lower incomplete gamma function.

Defined as

\[\log P(a, x) = \log \frac{1}{\Gamma(a)} \int_0^x t^{a-1} e^{-t} dt\]

for \(a > 0\) and \(x \geq 0\). This function is more accurate than computing log(gammainc(a, x)) directly.

Parameters:
aarray_like

Positive real parameter.

xarray_like

Nonneg real argument.

outndarray, optional

Optional output array for the function values.

Returns:
scalar or ndarray

Values of the log of the regularized lower incomplete gamma function.

See also

gammainc

regularized lower incomplete gamma function

gammaincc

regularized upper incomplete gamma function

log_gammaincc

log of the regularized upper incomplete gamma function

Notes

This function wraps the lgamma_p routine from the Boost Math C++ library [1].

Array API Standard Support

log_gammainc has 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 typically none of the other ufunc kwargs. out is 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. out is never supported for JAX because JAX arrays are immutable. log_gammainc does not currently support out for the PyTorch backend.

See Array API coverage for more information.

References

[1]

The Boost Developers. “Boost C++ Libraries”. https://www.boost.org/.

Examples

This function is useful when the naive computation log(gammainc(a, x)) underflows for small values.

>>> import numpy as np
>>> from scipy.special import log_gammainc, gammainc
>>> with np.errstate(divide='ignore'):
...    print(np.log(gammainc(500, 30)))
-inf
>>> log_gammainc(500, 30)
-940.6700276993504