Estimate the area represented by sampled observations.
Numerical integration of measurements
SciPy · Function
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.
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.
scipy.integrate.simpson(y, x=None, *, dx=1.0, axis=-1)| Name | Type | Description |
|---|---|---|
y | array_like | Array of values to integrate. |
x | array_like, optional | Optional sample coordinates corresponding to y. |
dx | float, optional | Uniform spacing of integration points; used only when x is None. Default: 1. |
axis | int, optional | Axis along which to integrate. Default: -1. |
float — the estimated integral computed with the composite Simpson’s rule.
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.
Numerical integration of measurements
Integration of multidimensional arrays
Known nonuniform coordinates
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.
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.
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.quadscipy.integrate.trapezoidscipy.integrate.cumulative_simpson