The evaluation is carried out using the relation to the incomplete gamma
integral (regularized gamma function).
Wrapper for the Cephes [1] routine gdtrc. Calling gdtrc directly can
improve performance compared to the sf method of scipy.stats.gamma
(see last example below).
Array API Standard Support
gdtrc has experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_ARRAY_API=1 and providing
CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
combinations of backend and device (or other capability) are supported.
gdtrc can evaluate different parameter sets by providing arrays with
broadcasting compatible shapes for a, b and x. Here we compute the
function for three different a at four positions x and b=3,
resulting in a 3x4 array.
The gamma distribution is also available as scipy.stats.gamma.
Using gdtrc directly can be much faster than calling the sf method
of scipy.stats.gamma, especially for small arrays or individual
values. To get the same results one must use the following parametrization:
stats.gamma(b,scale=1/a).sf(x)=gdtrc(a,b,x).
>>> fromscipy.statsimportgamma>>> a=2>>> b=3>>> x=1.>>> gdtrc_result=gdtrc(a,b,x)# this will often be faster than below>>> gamma_dist_result=gamma(b,scale=1/a).sf(x)>>> gdtrc_result==gamma_dist_result# test that results are equalTrue