Continuous interval modeling
Modeling a quantity with equal density across a bounded interval.
SciPy · Function
scipy.stats.uniform represents a continuous uniform distribution. Its standard support is [0, 1]; loc shifts the lower endpoint and scale sets the interval width.
scipy.stats.uniform is a continuous distribution object with support from loc through loc + scale. Use its inherited distribution methods for density, probabilities, quantiles, moments, and random variates; calling it with parameters creates a frozen distribution that retains them.
scipy.stats.uniform(loc=0, scale=1)| Name | Type | Description |
|---|---|---|
loc | array_like, optional | Location parameter; the lower endpoint of the distribution's support. Defaults to 0. |
scale | array_like, optional | Scale parameter; the support width. The upper endpoint is loc + scale; defaults to 1. |
size | int or tuple of ints, optional | Number or shape of random variates returned by rvs; defaults based on input arguments. |
moments | str, optional | Requested moments for stats, selected using letters such as m, v, s, and k. |
A frozen continuous random-variable object when called with parameters; distribution methods return values appropriate to the selected operation.
scipy.stats.uniform models a continuous random variable whose density is constant over its interval.scale is the interval width, so the upper endpoint is computed as loc + scale, not supplied independently.uniform returns a frozen random-variable object; use that object when repeatedly evaluating the same parameterized distribution.from scipy.stats import uniform
x = uniform(loc=2, scale=3)
print(x.pdf(3.5))
print(x.cdf(4.0))
print(x.rvs(random_state=0, size=3))This creates a frozen uniform distribution on [2, 5], evaluates its density and cumulative probability, and draws three reproducible samples.
Modeling a quantity with equal density across a bounded interval.
Generating random test inputs within configurable bounds.
Computing densities, cumulative probabilities, quantiles, and moments for a uniform model.
loc and scale change the support of scipy.stats.uniform?The standard distribution is uniform on [0, 1]. loc shifts the lower endpoint, while scale determines the interval width, producing support [loc, loc + scale].
Follow-up: How would you represent a uniform distribution on [a, b]? Use loc=a and scale=b-a, assuming b is greater than a.
uniform?The object inherits generic methods from rv_continuous, including methods for probabilities, density, moments, quantiles, and random variates. For example, pdf, cdf, ppf, stats, and rvs can be used on the distribution object.
Follow-up: Why use a frozen object? It stores the chosen parameters once, making repeated method calls less error-prone and easier to read.
uniform random variable?Calling the distribution with location and scale parameters creates a frozen continuous random-variable object. Its methods then use those fixed parameters automatically.
Follow-up: What must be checked when converting [a, b] into loc and scale? Ensure the width b-a is positive.
scipy.stats.rv_continuousscipy.stats.uniform.pdfscipy.stats.uniform.cdfscipy.stats.uniform.ppfscipy.stats.uniform.rvsscipy.stats.uniform.stats