Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

stats.binom

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.

How it works

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.

Syntax

scipy.stats.binom

Parameters

NameTypeDescription
narray_likeNumber of trials; shape parameter.
parray_likeProbability of a single success; shape parameter, constrained to 0 through 1.
locarray_like, optionalLocation parameter used to shift the distribution; default is 0.

Returns

A binomial discrete random-variable object, exposed as scipy.stats.binom, with inherited rv_discrete methods.

Key points

  • binom is SciPy's object for a binomial discrete distribution.
  • It inherits the standard discrete-distribution API, so methods such as pmf, cdf, mean, and rvs are available.
  • For an integer success count k, the PMF is \(\binom{n}{k}p^k(1-p)^{n-k}\).
  • The documented standardized support is integer k from 0 through n, and p must lie between 0 and 1.
  • Provide the trial count and single-trial success probability as the distribution's shape parameters.

Common mistakes

  • Use loc for a shifted distribution rather than changing the success count or probability.
  • Interpret p as the per-trial success probability; the complementary failure probability is 1 - p.

Example: Probability of an exact count

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.

When to use it

Exact-count probabilities

Evaluate the likelihood of an exact number of successes in repeated independent trials.

Threshold analysis

Compute cumulative probabilities or quantiles for a binomial count.

Random sampling

Generate simulated success counts for testing or Monte Carlo workflows.

Interview questions

QWhat does 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}\).

QHow do you calculate an exact probability?

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).

QWhat does the 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.hypergeom
  • scipy.stats.nbinom
  • scipy.stats.nhypergeom
  • scipy.stats.rv_discrete

Source: scipy.stats.binom. Checked 2026-10-15.