0
0
SciPydata~10 mins

2D interpolation (interp2d, griddata) 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 function used for 2D interpolation from scipy.interpolate.

SciPy
from scipy.interpolate import [1]
Drag options to blanks, or click blank then click option'
Ainterp2d
Binterp1d
Cgriddata1d
Dgriddata2d
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing interp1d which is for 1D interpolation.
Using griddata1d or griddata2d which are not valid function names.
2fill in blank
medium

Complete the code to create a 2D interpolation function using interp2d with linear method.

SciPy
f = interp2d(x, y, z, kind=[1])
Drag options to blanks, or click blank then click option'
A'nearest'
B'cubic'
C'linear'
D'quadratic'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cubic' or 'quadratic' which are more complex interpolation methods.
Using 'nearest' which picks the nearest point without interpolation.
3fill in blank
hard

Fix the error in the code to interpolate values at new points using griddata.

SciPy
from scipy.interpolate import griddata
points = np.array([[0, 0], [1, 1], [2, 2]])
values = np.array([0, 1, 4])
new_points = np.array([[1, 0], [2, 1]])
result = griddata(points, values, [1], method='linear')
Drag options to blanks, or click blank then click option'
Anew_points
Bpoints
Cvalues
Dmethod
Attempts:
3 left
💡 Hint
Common Mistakes
Passing known points or values instead of new points to interpolate.
Passing method as the third argument instead of as a keyword argument.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

SciPy
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the word in the condition instead of checking its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values only if value is positive.

SciPy
{ [1]: [2] for ([3], [2]) in data.items() if [2] > 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of uppercase.
Using v in the loop variable instead of k, v.
Not filtering values greater than zero.