0
0
SciPydata~10 mins

Linear vs cubic interpolation in SciPy - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the interpolation function from scipy.

SciPy
from scipy.interpolate import [1]
Drag options to blanks, or click blank then click option'
Ainterp
Binterpolate
Cinterp1d
Dinterpolator
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'interpolate' instead of 'interp1d'.
Trying to import a non-existent function like 'interp'.
2fill in blank
medium

Complete the code to create a linear interpolation function for given x and y data.

SciPy
f_linear = interp1d(x, y, kind=[1])
Drag options to blanks, or click blank then click option'
A'nearest'
B'cubic'
C'quadratic'
D'linear'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cubic' when linear interpolation is needed.
Omitting quotes around the kind value.
3fill in blank
hard

Fix the error in the code to create a cubic interpolation function.

SciPy
f_cubic = interp1d(x, y, kind=[1])
Drag options to blanks, or click blank then click option'
A'cubic'
B'linear'
C'nearest'
D'quadratic'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'linear' instead of 'cubic'.
Using 'quadratic' which is different from cubic.
4fill in blank
hard

Fill both blanks to create a dictionary of interpolated values using linear and cubic methods for new x points.

SciPy
results = {
    'linear': f_linear([1]),
    'cubic': f_cubic([2])
}
Drag options to blanks, or click blank then click option'
Ax_new
Bx_old
Cy_new
Dy_old
Attempts:
3 left
💡 Hint
Common Mistakes
Using old x or y values instead of new x values.
Mixing y values as input to interpolation functions.
5fill in blank
hard

Fill all three blanks to plot original data points and both linear and cubic interpolation curves.

SciPy
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()
Drag options to blanks, or click blank then click option'
Ax_new
B'linear'
C'cubic'
Dx_old
Attempts:
3 left
💡 Hint
Common Mistakes
Using old x points for interpolation plots.
Using wrong label keys in the results dictionary.