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

SciPy · Function

stats.bootstrap

Computes a bootstrap confidence interval for a statistic by repeatedly resampling input data with replacement. The default BCa method can account for bias and skew in the bootstrap distribution.

Since
1.7.0

How it works

The function repeatedly samples each input with replacement, evaluates the statistic on every resample, and uses the resulting bootstrap distribution to construct a confidence interval. Its default BCa method adjusts the interval using bias and acceleration; percentile and basic methods are also available.

Syntax

scipy.stats.bootstrap(data, statistic, *, n_resamples=9999, batch=None, vectorized=None, paired=False, axis=0, confidence_level=0.95, alternative='two-sided', method='BCa', bootstrap_result=None, rng=None, random_state=None)

Parameters

NameTypeDescription
datatuple of array-likeTuple of sample arrays containing the observations to resample.
statisticcallableCallable that computes the statistic from one or more samples.
n_resamplesintNumber of bootstrap resamples; default 9999.
batchint or NoneNumber of resamples processed in a batch; default None.
vectorizedbool or NoneWhether statistic supports vectorized evaluation; default None infers this.
pairedboolWhether input samples are paired and must use shared resample indices.
axisintAxis along which observations are arranged; default 0.
confidence_levelfloatConfidence level between 0 and 1; default 0.95.
alternative{'two-sided', 'less', 'greater'}Interval alternative: 'two-sided', 'less', or 'greater'.
method{'BCa', 'percentile', 'basic'}Interval construction method: 'BCa', 'percentile', or 'basic'.
bootstrap_resultBootstrapResult or NonePreviously computed BootstrapResult whose resamples may be reused.
rngnumpy.random.Generator or seed-likeRandom-number Generator or seed specification.

Returns

A BootstrapResult containing confidence_interval, standard_error, and the bootstrap distribution.

Key points

  • The function estimates uncertainty around a statistic by returning a bootstrap confidence interval.
  • Each bootstrap replicate independently resamples every supplied sample with replacement.
  • SciPy evaluates the chosen statistic on every collection of resampled inputs.
  • For a two-sided percentile interval, the bounds are centered symmetrically around the bootstrap distribution's median.

Example: Bootstrap mean confidence interval

import numpy as np
from scipy.stats import bootstrap

rng = np.random.default_rng(42)
data = (rng.normal(size=30),)
result = bootstrap(data, np.mean, rng=rng)
print(result.confidence_interval.low)
print(result.confidence_interval.high)

Computes a reproducible 95% BCa confidence interval for the sample mean.

When to use it

Nonparametric uncertainty estimation

Estimate uncertainty for a sample mean, median, percentile, or another statistic without assuming a parametric distribution.

Paired-sample analysis

Quantify uncertainty for a statistic computed from matched observations in multiple arrays.

Efficient repeated analysis

Reuse bootstrap work or tune batch processing when running many resamples or large arrays.

Interview questions

QWhat does scipy.stats.bootstrap compute?

It generates resamples with replacement, evaluates the statistic for each resample, and derives a confidence interval from the resulting distribution. The default interval method is BCa.

Follow-up: How can repeated calls be made reproducible? Pass a seeded NumPy Generator through rng.

QHow are input samples and statistics represented?

The data argument is a tuple of sample arrays, while statistic is the callable evaluated on each resample. The callable can operate on one or multiple samples, depending on the statistic and paired setting.

Follow-up: When should paired=True be used? Use it when corresponding observations in separate samples must be resampled together.

QWhich parameters control computation size?

n_resamples controls the number of bootstrap replicates and defaults to 9999. batch controls how many resamples are processed together, allowing memory use to be managed.

Follow-up: What is the trade-off of reducing batch? It lowers peak memory consumption but may increase execution overhead.

  • scipy.stats.bootstrap.BootstrapResult
  • scipy.stats.confidence_interval

Source: Bootstrap. Checked 2026-10-15.