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

SciPy · Function

integrate.simpson

Estimates an integral from sampled data with the composite Simpson rule. Provide x for sample coordinates or use dx for uniform spacing, and choose the integration dimension with axis.

How it works

Pass sampled values in y and optionally their coordinates in x. When x is omitted, SciPy treats samples as evenly spaced by dx; axis selects the dimension integrated, and the result is the composite Simpson-rule estimate.

Syntax

scipy.integrate.simpson(y, x=None, *, dx=1.0, axis=-1)

Parameters

NameTypeDescription
yarray_likeArray of values to integrate.
xarray_like, optionalOptional sample coordinates corresponding to y.
dxfloat, optionalUniform spacing of integration points; used only when x is None. Default: 1.
axisint, optionalAxis along which to integrate. Default: -1.

Returns

float — the estimated integral computed with the composite Simpson’s rule.

Key points

  • The function estimates an integral from sampled values using the composite Simpson rule along one array axis.
  • Omitting x makes SciPy interpret the samples as uniformly spaced according to dx.
  • Use x to provide the coordinates associated with the sampled y values.
  • dx represents the uniform spacing between integration points when x is not supplied.
  • axis chooses which dimension of y is reduced by the integration.
  • The return value is a floating-point estimate of the integral.

Common mistakes

  • dx has no effect when x is supplied; use x to describe the sample locations.
  • For multidimensional arrays, explicitly set axis when the data dimension to integrate is not the last one.

Example: Integrate sampled data

import numpy as np
from scipy.integrate import simpson

x = np.linspace(0, np.pi, 101)
y = np.sin(x)
area = simpson(y, x=x)
print(area)

Integrates sampled sine values over their explicitly supplied, possibly nonuniform coordinate array.

When to use it

Estimate the area represented by sampled observations.

Numerical integration of measurements

Reduce one selected data dimension while preserving the others.

Integration of multidimensional arrays

Integrate values whose sample locations are supplied explicitly through x.

Known nonuniform coordinates

Interview questions

QWhat does scipy.integrate.simpson compute?

simpson applies the composite Simpson rule to sampled values along the selected axis. It returns the estimated integral, using x for sample coordinates or dx for uniform spacing when x is omitted.

Follow-up: What happens if the samples are not evenly spaced? Supply x; do not rely on dx, because dx is only used when x is None.

QWhat are the main parameters?

y contains the values to integrate. x optionally supplies the points where those values were sampled; otherwise dx specifies uniform spacing and defaults to 1.0.

Follow-up: How would you integrate along a non-final dimension of a multidimensional array? Pass that dimension through axis.

QHow does axis affect the result?

axis identifies the dimension integrated and defaults to -1, the last axis. The function returns a float containing the estimated composite-Simpson integral.

Follow-up: What should be checked when integrating array data? Confirm that the intended sample dimension is selected and that x or dx correctly represents spacing.

  • scipy.integrate.quad
  • scipy.integrate.trapezoid
  • scipy.integrate.cumulative_simpson

Source: simpson. Checked 2026-10-15.