0
0
SciPydata~10 mins

Spline interpolation in SciPy - Interactive Code Practice

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

Complete the code to import the spline interpolation function from scipy.

SciPy
from scipy.interpolate import [1]
Drag options to blanks, or click blank then click option'
AUnivariateSpline
Bspline
Cinterp1d
Dgriddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'interp1d' which is for linear or other simple interpolations, not splines.
Using 'spline' which is deprecated in scipy.
Using 'griddata' which is for scattered data interpolation.
2fill in blank
medium

Complete the code to create a spline interpolation object for given x and y data.

SciPy
spline = UnivariateSpline(x, [1])
Drag options to blanks, or click blank then click option'
Az
Bw
Ct
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing unrelated variables instead of y data.
Confusing x and y variables.
3fill in blank
hard

Fix the error in the code to evaluate the spline at new points.

SciPy
y_new = spline([1])
Drag options to blanks, or click blank then click option'
Ax
Bx_new
Cy_new
Dnew_x
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the original x or y data instead of new points.
Using undefined variables.
4fill in blank
hard

Fill both blanks to create a dictionary of squared errors for points where y is greater than 0.

SciPy
errors = {x: (y - spline(x))[1]2 for x, y in zip(x_vals, y_vals) if y [2] 0}
Drag options to blanks, or click blank then click option'
A**
B>
C<
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of power for squaring.
Using wrong comparison operators.
5fill in blank
hard

Fill all three blanks to create a dictionary of absolute errors for points where y is less than 5.

SciPy
abs_errors = [1]: abs([2] - spline([1])) for [1] , [2] in zip(x_vals, y_vals) if [2] [3] 5}
Drag options to blanks, or click blank then click option'
Ax
By
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up x and y in the dictionary comprehension.
Using wrong comparison operators.