Probability-density evaluation
Compute likelihoods or densities for nonnegative continuous measurements.
SciPy · Function
scipy.stats.gamma is SciPy’s continuous gamma random-variable object. Provide a positive shape a, optionally shift with loc and scale with scale, then evaluate probabilities or generate samples.
gamma is SciPy’s continuous gamma-distribution object. Supply the positive shape a, then use inherited distribution methods such as pdf, cdf, or rvs; loc shifts the distribution and scale stretches it, while calling gamma(a, ...) creates a frozen object with parameters retained.
scipy.stats.gamma(a, loc=0, scale=1)| Name | Type | Description |
|---|---|---|
a | array_like | Shape parameter; the documented gamma distribution requires a > 0. |
loc | array_like, optional | Location parameter used to shift the distribution; default is 0. |
scale | array_like, optional | Scale parameter used to scale the distribution; default is 1. |
The distribution object provides continuous-random-variable methods; calling it with parameters returns a frozen continuous random-variable object.
scipy.stats.gamma represents a continuous gamma random variable.a as the distribution’s shape parameter.x^(a-1) exp(-x) / Gamma(a) on x >= 0, with a > 0.loc to translate the distribution and scale to change its spread.erlang and expon as related distributions.scale for the scale convention documented by SciPy; a rate parameter beta corresponds to scale = 1 / beta, not scale = beta.from scipy.stats import gamma
shape = 2.0
x = 3.0
pdf = gamma.pdf(x, a=shape)
sample = gamma.rvs(a=shape, size=5, random_state=0)
print(pdf)
print(sample)Evaluates the gamma density at one point and generates reproducible random variates.
Compute likelihoods or densities for nonnegative continuous measurements.
Generate simulated observations from a gamma model.
Model waiting times, durations, or aggregate positive quantities with adjustable shape and scale.
scipy.stats.gamma?a is the shape parameter and must be positive. The standard density is proportional to x**(a-1) * exp(-x) divided by the gamma function, for nonnegative x.
Follow-up: How would you use a rate parameter β? Use SciPy’s scale=1 / β, because its documented alternative parameterization uses rate as the reciprocal of scale.
loc and scale do?loc shifts the distribution and scale scales it. For the standard gamma form, the density is defined for x >= 0; applying loc changes the location through the usual continuous-distribution transformation.
Follow-up: How can repeated evaluations avoid passing parameters each time? Call gamma(a, loc=..., scale=...) to obtain a frozen continuous random-variable object.
The object provides generic continuous-distribution methods, including rvs for random variates and pdf for the probability density function. For example, gamma.pdf(x, a) evaluates the density and gamma.rvs(a, size=...) samples values.
Follow-up: Which related distributions should you check for special cases? The documentation lists erlang and expon; integer a gives Erlang, while a=1 gives exponential.
scipy.stats.erlangscipy.stats.expon