0
0
SciPydata~10 mins

Sparse iterative solvers (gmres, cg) 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 GMRES solver from scipy.

SciPy
from scipy.sparse.linalg import [1]
Drag options to blanks, or click blank then click option'
Acg
Bgmres
Csolve
Dinv
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'cg' instead of 'gmres'.
Trying to import 'solve' which is not an iterative solver.
Using 'inv' which is for matrix inversion.
2fill in blank
medium

Complete the code to solve a linear system using the CG solver.

SciPy
x, info = [1](A, b)
Drag options to blanks, or click blank then click option'
Asolve
Binv
Cgmres
Dcg
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'solve' which is a direct solver, not iterative.
Using 'inv' which computes matrix inverse.
Using 'gmres' which is a different iterative solver.
3fill in blank
hard

Fix the error in the code to correctly call GMRES with a restart parameter of 50.

SciPy
x, info = gmres(A, b, restart=[1])
Drag options to blanks, or click blank then click option'
A50
B'50'
Crestart
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the restart value as a string.
Passing the parameter name as a value.
Passing None which disables restart.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if the 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)
Blen(word) > 3
Cword.startswith('a')
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using a wrong condition like startswith instead of length check.
Not using a condition at all.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values where values are greater than zero.

SciPy
result = [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
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable names in the loop.
Not converting keys to uppercase.
Using incorrect variable names for values.