Latticework

Command Palette

Search for a command to run...

SciPy

Interpolation

16 min

Explanation

Given a handful of known (x, y) points, interpolation estimates y at some NEW x that falls between them — assuming some smooth relationship connects the known points. The simplest version, linear interpolation, just draws a straight line between each pair of adjacent known points and reads off where the query x lands on that line.

from scipy.interpolate import interp1d

def interpolate_value(x_known, y_known, x_query):
    f = interp1d(x_known, y_known)
    return round(float(f(x_query)), 4)
Try it

interp1d is 'linear' by default, but scipy also supports 'cubic' and other smoother interpolation kinds -- the same core idea (estimate between known points) with a curve instead of straight-line segments, useful when the underlying data is known to be smoother than a jagged piecewise-linear fit suggests.

Loading editor…
Exercise

Write `interpolate_value(x_known, y_known, x_query)`: use `scipy.interpolate.interp1d` to build a linear interpolator from the known points, then return its estimate at `x_query`, rounded to 4 decimal places.

Quiz

What is interpolation actually doing, conceptually, when it estimates a value at an x between two known data points?

Checkpoint

You can interpolate estimated values between known data points using scipy.interpolate, and understand interpolation as an assumption-based estimate, not a measured value.