Imagine you have temperature readings at 9 AM and 11 AM, but you want to know the temperature at 10 AM. Why does interpolation help estimate this missing value?
Think about how you connect dots on a graph to find points in between.
Interpolation uses the known data points to create a smooth curve or line, estimating values between those points logically and consistently.
What is the output of this code that uses linear interpolation to estimate a value between two points?
import numpy as np from scipy.interpolate import interp1d x = np.array([0, 5]) y = np.array([0, 10]) linear_interp = interp1d(x, y) result = linear_interp(3) print(result)
Linear interpolation finds a point on the straight line between (0,0) and (5,10).
At x=3, the linear interpolation calculates y as 6 because the slope is 2 (10/5), so y=2*3=6.
Given these data points, what are the interpolated values at x=2 and x=4 using cubic interpolation?
import numpy as np from scipy.interpolate import interp1d x = np.array([1, 3, 5, 7]) y = np.array([2, 8, 18, 32]) cubic_interp = interp1d(x, y, kind='cubic') result = [float(cubic_interp(2)), float(cubic_interp(4))] print(result)
Cubic interpolation fits a smooth curve through all points, estimating values between them.
The cubic interpolation estimates y values at x=2 and x=4 as approximately 6.0 and 14.0 respectively, based on the smooth curve fit.
What error does this code produce when trying to interpolate a value outside the data range?
import numpy as np from scipy.interpolate import interp1d x = np.array([0, 1, 2]) y = np.array([0, 1, 4]) interp = interp1d(x, y) print(interp(3))
Check if the interpolation function allows values outside the original x range.
By default, interp1d does not allow extrapolation and raises a ValueError if the input is outside the x range.
You have noisy sensor data points and want to estimate smooth values between them. Which interpolation method is best to reduce sharp jumps?
Think about which method creates smooth curves rather than straight lines or steps.
Cubic spline interpolation fits smooth curves through data points, reducing sharp jumps and noise effects better than linear or nearest neighbor methods.