scipy.interpolate fills gaps between known points—interp1d, splines (make_interp_spline), and grid data for 2D surfaces.
Use cases
- Resample irregular time series to uniform grid
- Smooth curves between experimental readings
- Evaluate functions between tabulated values
1D linear interp
import numpy as np
from scipy import interpolate
x = np.array([0, 1, 3, 4], dtype=float)
y = np.array([0, 2, 2, 4], dtype=float)
f = interpolate.interp1d(x, y, kind='linear')
print('f(2):', f(2.0))
Extrapolation caution
Default interp1d may extrapolate wildly outside data range—set bounds_error=True or fill_value for production.
Important interview questions and answers
- Q: linear vs cubic spline?
A: Linear: no overshoot; cubic: smoother but can oscillate between points. - Q: Extrapolation risk?
A: Model undefined outside measured range—flag or clamp explicitly.
Self-check
- When is interpolation appropriate?
- What does kind='linear' assume between points?
Pitfall: Extrapolating outside measured x range—set bounds_error=True or explicit fill_value.
Interview prep
- interp1d?
1D interpolation between tabulated points.
- Extrapolation?
Dangerous outside data—set bounds_error or fill_value.