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

SciPy · Function

stats.t

scipy.stats.t represents a continuous Student’s t random variable. Set its positive degrees of freedom with df, and use inherited methods for densities, probabilities, quantiles, and sampling.

How it works

scipy.stats.t is a continuous Student’s t distribution object. Supply the degrees of freedom through df, then use inherited distribution methods such as pdf, cdf, ppf, and rvs; loc and scale can shift and rescale the distribution.

Syntax

scipy.stats.t

Parameters

NameTypeDescription
xarray_likeEvaluation point or array of points for distribution methods such as pdf and cdf.
dfarray_likeDegrees of freedom; the shape parameter, required to be positive.
locarray_like, optionalLocation parameter used to shift the distribution; default is 0.
scalearray_like, optionalScale parameter used to rescale the distribution; default is 1.

Returns

Distribution-method calls return the corresponding result, such as a density, cumulative probability, quantile, or random variates, depending on the selected inherited method.

Key points

  • The object models the Student’s t distribution for continuous-valued random variables.
  • It inherits common continuous-distribution methods, including density, cumulative probability, quantile, and random-variates operations.
  • Use scipy.stats.nct when the required model is the noncentral t distribution.
  • A location-scale parameterization evaluates the standardized density and divides it by the scale.

Common mistakes

  • Use loc and scale for location and scale changes rather than modifying the standard distribution manually.

Example: Evaluate and sample a t distribution

from scipy.stats import t

probability = t.cdf(1.96, df=10)
quantile = t.ppf(0.975, df=10)
samples = t.rvs(df=10, size=4, random_state=0)

print(probability)
print(quantile)
print(samples)

Computes a cumulative probability, a quantile, and four random variates from a Student’s t distribution with 10 degrees of freedom.

When to use it

Statistical inference

Compute tail probabilities or critical values for inference involving a t-distributed statistic.

Density evaluation

Evaluate likelihood or density values for continuous observations under a t model.

Random sampling

Generate simulated observations with specified degrees of freedom.

Interview questions

QWhat does scipy.stats.t represent?

It represents a Student’s t continuous random variable. The object is an rv_continuous instance, so it provides generic distribution operations supplemented with t-specific behavior.

Follow-up: How would you model a noncentral t distribution? Use the related scipy.stats.nct distribution instead.

QWhat are the main parameters of the t distribution?

df is the shape parameter and must be greater than zero. loc shifts the distribution, while scale rescales it.

Follow-up: What constraint applies to the scale parameter? It must be positive for a valid continuous distribution parameterization.

QHow do loc and scale affect the density?

For a shifted and scaled variable, standardize with y = (x - loc) / scale; the density is the standard density at y, divided by scale. This lets the inherited methods operate on nonstandard location and scale settings.

Follow-up: Which method returns a probability threshold? Use ppf, the percent-point function, with a probability between zero and one.

  • scipy.stats.nct
  • scipy.stats.rv_continuous

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