Exact-count probabilities
Evaluate the likelihood of an exact number of successes in repeated independent trials.
SciPy · Function
scipy.stats.binom is a binomial discrete random variable for modeling success counts across n trials with per-trial success probability p. It provides standard discrete-distribution methods and supports shifting with loc.
binom models the number of successes in a fixed number of independent trials. Supply n and p as shape parameters, then use inherited distribution methods such as pmf, cdf, mean, or rvs; loc can shift the support.
scipy.stats.binom| Name | Type | Description |
|---|---|---|
n | array_like | Number of trials; shape parameter. |
p | array_like | Probability of a single success; shape parameter, constrained to 0 through 1. |
loc | array_like, optional | Location parameter used to shift the distribution; default is 0. |
A binomial discrete random-variable object, exposed as scipy.stats.binom, with inherited rv_discrete methods.
binom is SciPy's object for a binomial discrete distribution.pmf, cdf, mean, and rvs are available.k, the PMF is \(\binom{n}{k}p^k(1-p)^{n-k}\).k from 0 through n, and p must lie between 0 and 1.loc for a shifted distribution rather than changing the success count or probability.p as the per-trial success probability; the complementary failure probability is 1 - p.from scipy.stats import binom
n = 10
p = 0.4
probability = binom.pmf(3, n, p)
print(probability)Computes the probability of exactly three successes in ten independent trials with success probability 0.4.
Evaluate the likelihood of an exact number of successes in repeated independent trials.
Compute cumulative probabilities or quantiles for a binomial count.
Generate simulated success counts for testing or Monte Carlo workflows.
scipy.stats.binom model?binom represents a binomial discrete random variable. Its shape parameters are n, the number of trials, and p, the probability of success on one trial.
Follow-up: What is its probability mass function? For an integer k from 0 through n, it is \(\binom{n}{k}p^k(1-p)^{n-k}\).
Use binom.pmf(k, n, p) for the probability of exactly k successes. The object also inherits generic methods from rv_discrete, including cumulative-probability and random-variates methods.
Follow-up: How would you obtain the probability of at most k successes? Use binom.cdf(k, n, p).
loc parameter do?The distribution's standardized support is the integer range from 0 to n, with n and p defining the distribution. A loc value shifts that distribution.
Follow-up: What equivalent expression represents the shift for the PMF? binom.pmf(k, n, p, loc) equals binom.pmf(k - loc, n, p).
scipy.stats.hypergeomscipy.stats.nbinomscipy.stats.nhypergeomscipy.stats.rv_discrete