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

SciPy · Module

scipy.stats

scipy.stats is SciPy’s broad statistics module, combining probability distributions with summary statistics, correlations, tests, density estimation, masked-array tools, and quasi-Monte Carlo functionality. It supports both continuous and discrete univariate distributions.

How it works

Importing scipy.stats exposes probability distributions and statistical routines for descriptive statistics, correlations, hypothesis tests, masked-array statistics, kernel density estimation, and quasi-Monte Carlo work. Its distributions include continuous and discrete families, while many functions operate along array axes and offer options for missing values or bias handling.

Syntax

import scipy.stats

Key points

  • The module groups distribution models with descriptive, frequency, correlation, and hypothesis-testing tools.
  • It also covers masked statistics, kernel density estimation, and quasi-Monte Carlo functionality.
  • Univariate distributions use rv_continuous for continuous laws and rv_discrete for discrete laws.
  • The page organizes the public API into overview tables covering different statistical categories.
  • The describe function summarizes an input array with multiple descriptive measures.

Common mistakes

  • Use scipy.stats.mstats when the data are masked arrays; the regular scipy.stats functions may not provide the masked-array behavior you need.
  • SciPy does not cover every statistics task; specialized areas such as regression and time-series analysis may require another package.

Example: Describe a sample

from scipy import stats

sample = [1, 2, 2, 3, 4]
result = stats.describe(sample)
print(result.mean, result.variance, result.minmax)

This computes descriptive statistics for a sample and prints selected fields from the returned result.

When to use it

Exploratory data analysis

Analyze a numeric sample with descriptive measures such as mean, variance, skewness, or interquartile range.

Probability modeling

Evaluate probability models and generate or transform values using continuous or discrete distributions.

Inference and relationships

Run statistical tests and correlation calculations on experimental or observational data.

Density and sampling workflows

Use kernel density estimation or quasi-Monte Carlo methods for numerical statistical workflows.

Interview questions

QWhat does scipy.stats provide?

scipy.stats is a module containing probability distributions plus statistical functions for summaries, frequencies, correlations, tests, masked statistics, kernel density estimation, and quasi-Monte Carlo. It includes both continuous and discrete distribution families.

Follow-up: How are univariate distributions represented? Each univariate distribution is an instance of a subclass of rv_continuous, or rv_discrete for discrete distributions.

QHow would you obtain descriptive statistics?

Use scipy.stats.describe for several descriptive statistics of an array. The module also exposes focused routines such as gmean, hmean, skew, kstat, and iqr.

Follow-up: Which routine computes a geometric mean? scipy.stats.gmean computes it along a specified axis and supports dtype and, in the current documentation, weighting and NaN-policy options.

QHow does scipy.stats relate to mstats and other statistics packages?

The module includes counterparts in scipy.stats.mstats for masked arrays. The documentation also identifies areas outside SciPy's scope, so choosing a specialized package can be appropriate for some statistical problems.

Follow-up: Why might ordinary scipy.stats functions be unsuitable for masked data? They are not the masked-statistics interface; use the corresponding mstats function when masked-array semantics are required.

  • scipy.stats.describe
  • scipy.stats.gmean
  • scipy.stats.hmean
  • scipy.stats.skew
  • scipy.stats.kstat
  • scipy.stats.iqr
  • scipy.stats.mstats

Source: Statistical functions (scipy.stats) — SciPy v1.18.0 Manual. Checked 2026-10-15.