0
0
SciPydata~10 mins

UnivariateSpline 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 UnivariateSpline class from scipy.interpolate.

SciPy
from scipy.interpolate import [1]

spline = UnivariateSpline(x, y)
Drag options to blanks, or click blank then click option'
AUnivariateSpline
Binterp1d
Csplrep
Dsplev
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong function like interp1d which is for linear interpolation.
Using splrep or splev which are lower-level spline functions.
2fill in blank
medium

Complete the code to create a UnivariateSpline object with data arrays x and y.

SciPy
spline = UnivariateSpline([1], y)
Drag options to blanks, or click blank then click option'
At
Bx
Cz
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing y as the first argument instead of x.
Using undefined variables like z or t.
3fill in blank
hard

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

SciPy
y_new = spline([1])
Drag options to blanks, or click blank then click option'
Ax_new
Bx
Cy
Dnew_x
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the original x array instead of the new points.
Using undefined variable names like new_x without defining them.
4fill in blank
hard

Fill both blanks to create a UnivariateSpline with smoothing factor s=1 and evaluate it at x_new.

SciPy
spline = UnivariateSpline(x, y, [1]=[2])
y_new = spline(x_new)
Drag options to blanks, or click blank then click option'
As
B1
Csmooth
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'smooth' instead of 's' as the parameter name.
Setting smoothing to 0 which fits the spline exactly through points.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping words to their lengths for words longer than 3 characters that contain the letter 'a'.

SciPy
lengths = {word: [1] for word in words if len(word) [2] 3 and 'a' [3] word}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
Ccontains
Din
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which is not a Python operator.
Reversing the 'in' operator like word in 'a'.