Complete the code to import the interpolation function from scipy.
from scipy.interpolate import [1]
The function interp1d is used for 1-dimensional interpolation in scipy.
Complete the code to create a linear interpolation function for given x and y data.
f_linear = interp1d(x, y, kind=[1])To create a linear interpolation, the kind parameter should be set to 'linear'.
Fix the error in the code to create a cubic interpolation function.
f_cubic = interp1d(x, y, kind=[1])The kind parameter must be set to 'cubic' to perform cubic interpolation.
Fill both blanks to create a dictionary of interpolated values using linear and cubic methods for new x points.
results = {
'linear': f_linear([1]),
'cubic': f_cubic([2])
}Both interpolation functions should be called with the new x values (x_new) to get interpolated y values.
Fill all three blanks to plot original data points and both linear and cubic interpolation curves.
plt.plot(x, y, 'o', label='data') plt.plot([1], results['linear'], label='linear') plt.plot([2], results[[3]], label='cubic') plt.legend() plt.show()
We plot the interpolated values against the new x points. The label for cubic interpolation is 'cubic'.