scipy.integrate is a collection of numerical methods, not one universal integration function. Choose a method based on what you have: use quad for a callable function and bounds, multidimensional routines for nested integrals, sampled-data methods for values measured at points, and solve_ivp for an ordinary differential equation’s initial-value problem. The last task is related to integration, but it is not the same as calculating a definite integral.
Choose a method from the form of your problem
| What you have or need | Useful starting point | Problem type and key qualification |
|---|---|---|
| A callable function of one variable and integration bounds | quad |
One-dimensional quadrature; supports finite and infinite bounds and returns an estimated integral and absolute-error estimate. |
| A callable function integrated over multiple variables | dblquad, tplquad, or nquad |
Multidimensional quadrature; nested bounds need to match the order of integration. |
| Function values already sampled at points | trapezoid, simpson, or romb |
Quadrature from data rather than repeated evaluation of a callable integrand. romb requires equally spaced samples and a sample count of 2k + 1. |
| A changing state described by a differential equation and initial conditions | solve_ivp |
An ODE initial-value problem, not a direct definite-integral calculation; the solver uses tolerances to control its numerical steps. |
The official SciPy integration tutorial introduces these method families. Individual API details can vary by release; the quad and simpson references cited here are labeled SciPy v1.18.0, while the linked solve_ivp reference is v1.15.3.
Integrate a callable function with quad
For a one-variable function known as code, scipy.integrate.quad is the usual starting point. It uses QUADPACK and can integrate over finite or infinite bounds. Its result includes both an estimated value and an estimate of absolute error; the latter helps assess the calculation but is not a proof that the answer is correct.
For example, for an integrand f over bounds a and b, the core call has the form quad(f, a, b). See the SciPy v1.18.0 quad API reference for the version-specific signature and options.
#1 Best Overall
Handle multidimensional integrals with nested bounds
For two or three variables, SciPy provides dblquad and tplquad; nquad supports integration across multiple variables. These routines evaluate multidimensional integrals through nested integrations. Their bounds are not interchangeable: define each inner range in the context of the variables on which it depends, and follow the wrapper’s expected order.
Nested numerical work also compounds uncertainty. The SciPy tutorial cautions that if an outer quad call evaluates an inner function that itself calls quad, the outer error bound may underestimate the inner calculation’s contribution to the total error. Check that the limits and order represent the intended region, and do not treat a single reported estimate as a full error analysis.
Rank #2
Integrate values sampled from data
If you have measurements or other values on a grid rather than a callable function, use sampled-data methods such as trapezoid and simpson. Supply the sample array and, when appropriate, its coordinates; the simpson API also accepts spacing dx and an axis for array inputs. The SciPy v1.18.0 simpson reference documents these inputs.
What Simpson’s rule guarantees—and what it does not
With an odd number of equally spaced samples, Simpson’s method is exact for polynomials of degree three or less. With non-equally spaced sample coordinates, its exactness is only through degree two. These are mathematical exactness conditions for those polynomial cases, not a general promise that measured or noisy data will be integrated accurately.
Recommended Free Tools
When to use romb
Romberg integration from sampled values is designed for equally spaced samples whose count is 2k + 1. If the sample spacing or count does not satisfy that requirement, choose a different method or prepare data on a suitable grid rather than assuming romb will fit arbitrary samples.
Solve an ODE initial-value problem with solve_ivp
solve_ivp solves a first-order system written as dy/dt = f(t, y), given an initial state. A higher-order equation can be rewritten as a first-order system by adding state variables for the unknown function and its derivatives. This produces a trajectory of states over time, rather than the single accumulated value returned by a definite-integral calculation.
The linked SciPy v1.15.3 solve_ivp API reference identifies RK45 as the default method. The solver can choose its steps automatically, while t_eval specifies times at which results should be reported; returned states are arranged in columns. Relative and absolute tolerances influence step control, but tighter tolerances alone do not validate the model or guarantee an accurate physical result.
For stiff problems or problems where a Jacobian is supplied, choose a solver that supports that option; the SciPy tutorial demonstrates this with Radau. Consult the API reference for the capabilities and options of the solver available in the SciPy release you use.
Best Value
Check bounds and sampling before trusting a result
Numerical integration algorithms sample the integrand at a finite number of points, as the SciPy tutorial explains. A narrow peak or other important feature can fall between sampled points, and an answer can look plausible despite missing it. A particularly broad finite interval can be a poor choice if nearly all the integrand’s contribution lies in a small region.
- Set bounds that closely enclose the region where the integrand matters, when the problem permits it.
- If the integrand has several important regions, split the interval so the calculation can resolve each one.
- For nested integrals, inspect the inner limits and account for numerical error in inner evaluations as well as the outer result.
- For sampled data, verify that the coordinates and spacing match the assumptions of the selected rule.
- For an ODE, distinguish requested output times from the solver’s internal step choices, and treat tolerance settings as numerical controls rather than evidence that the model itself is correct.
Use the SciPy generated reference index to locate documentation for other integration routines, and check the API pages for the installed SciPy version when behavior or options are release-sensitive.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




