The final chapter rounds out the toolkit with three more submodules you'll reach for in scientific and engineering work: interpolation (estimating between measurements), integration (area under a curve), and SciPy's richer linear algebra.
Interpolation
You measured a value at a few points and need an estimate between them. scipy.interpolate builds a function through your points that you can evaluate anywhere:
import numpy as npfrom scipy import interpolatex = np.array([0, 1, 2, 3, 4])y = np.array([0, 1, 4, 9, 16]) # measured pointsf = interpolate.interp1d(x, y, kind="cubic")f(2.5) # a smooth estimate at x = 2.5 (≈ 6.25)
Integration
scipy.integrate computes the area under a curve numerically — useful when there's no clean formula for the integral:
from scipy import integrate# Integrate f(x) = x^2 from 0 to 3 (exact answer = 9)area, err = integrate.quad(lambda x: x**2, 0, 3)print(area) # ≈ 9.0# From sampled data (no formula), use the trapezoidal ruley = np.array([0, 1, 4, 9])integrate.trapezoid(y, x=[0, 1, 2, 3])
Linear algebra
scipy.linalg extends NumPy's with more decompositions and solvers. Solving a linear system Ax = b is the workhorse:
from scipy import linalgA = np.array([[3, 1], [1, 2]])b = np.array([9, 8])x = linalg.solve(A, b) # solve Ax = b → [2. 3.]linalg.det(A) # determinantlinalg.inv(A) # inverse (prefer solve over inv for accuracy)
Practice
Interpolate a smooth curve through 5 measured points and estimate a value between two of them. Integrate a function of your choice with quad and check it against the exact answer. Solve a 2×2 linear system with linalg.solve.
Key takeaways
- 01scipy.interpolate estimates values between measured points (interpolation, not extrapolation).
- 02scipy.integrate.quad computes definite integrals; trapezoid works on sampled data.
- 03scipy.linalg.solve solves Ax = b — prefer it over computing the inverse.
- 04Extrapolating beyond your data range is risky — the fitted curve is unconstrained there.
- 05Across four chapters you now know SciPy's map: stats, optimize, interpolate, integrate, linalg.
