Interpolation
If you've measured a value at a handful of points, interpolation estimates what it probably was at the points in between — filling in the gaps in your data using the shape of the data you do have.
Linear interpolation with interp1d
interp1d takes your known x and y values and returns a function you can call with any new x to get an estimated y:
from scipy.interpolate import interp1d x = [0, 1, 2, 3, 4] y = [0, 1, 4, 9, 16] f = interp1d(x, y) print(f(2.5))
6.5
x and y here happen to be the squares of 0 through 4. f(2.5) falls exactly halfway between the known points (2, 4) and (3, 9), so by default interp1d draws a straight line between them and reads off the midpoint: 4 + 0.5 × (9 - 4) = 6.5. Note that's not the true value of 2.5² (which is 6.25) — linear interpolation approximates with straight lines, it doesn't recover the original curve.
Smoother interpolation with kind="cubic"
For data that follows a smooth curve, straight-line segments can look visibly jagged. Passing kind="cubic" fits a smoother curve through the same points instead:
from scipy.interpolate import interp1d x = [0, 1, 2, 3, 4] y = [0, 1, 4, 9, 16] f_cubic = interp1d(x, y, kind='cubic') print(f_cubic(2.5))
6.25
Because the underlying data is exactly x2, a cubic fit recovers the true value at 2.5 almost exactly. Real-world data is rarely this clean, but the general lesson holds: kind='cubic' tends to track a smooth underlying pattern more closely than straight-line segments do.
x values raises a ValueError rather than silently guessing — SciPy is being deliberately cautious, since extrapolation beyond your actual data is far less reliable than interpolation within it. If you genuinely need values outside that range, pass fill_value="extrapolate" explicitly, but treat anything it returns with real skepticism.scipy.optimize, working with probability distributions and descriptive statistics through scipy.stats, solving systems of equations with scipy.linalg, and estimating values between data points with scipy.interpolate. Together with the Python course this builds on, you now have a solid foundation for real numerical and scientific computing work.