Generalized factorial calculations
Convert factorial-like expressions involving non-integer or complex arguments into numerical values.
SciPy · Function
Computes the gamma function for real or complex scalar and array-like inputs. It generalizes factorials and optionally stores results in a supplied output array.
scipy.special.gamma evaluates the mathematical gamma function for real or complex scalar and array-like inputs. It supports analytic continuation beyond the defining integral's region and can write results into an optional output array.
scipy.special.gamma(z, out=None)| Name | Type | Description |
|---|---|---|
z | array_like | Real or complex valued argument. |
out | ndarray, optional | Optional array receiving the function values. |
scalar or ndarray: Values of the gamma function
import numpy as np
from scipy.special import gamma
x = np.array([1.0, 2.0, 3.0, 0.5])
print(gamma(x)) # [1. 1. 2. 1.77245385]Evaluates the gamma function elementwise for a NumPy array.
Convert factorial-like expressions involving non-integer or complex arguments into numerical values.
Evaluate special-function values across NumPy arrays without explicit Python loops.
Reuse preallocated storage during repeated array computations.
gamma(z) computes the gamma function, which generalizes factorials: for a natural number n, Γ(n + 1) equals n!. It accepts real or complex array-like input and returns a scalar or ndarray.
Follow-up: How can factorial values be expressed with gamma? For a nonnegative integer n, use gamma(n + 1), because the recurrence and Γ(1) = 1 establish that identity.
The defining integral applies when the real part of z is positive. SciPy extends the function to the rest of the complex plane through analytic continuation.
Follow-up: What happens at nonnegative integer poles? The function is singular there, and the limiting infinity sign depends on the approach direction.
The optional out argument supplies an ndarray that receives the computed values. This is useful when the caller wants results stored in preallocated output memory rather than a newly allocated result.
Follow-up: What input shapes are practical? Array-like inputs are handled elementwise, producing a scalar for scalar input or an ndarray for array input.
scipy.special.gammalnscipy.special.loggammascipy.special.rgamma