0
0
SciPydata~10 mins

Matrix inverse (inv) 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 that calculates the inverse of a matrix.

SciPy
from scipy.linalg import [1]

matrix = [[1, 2], [3, 4]]
inv_matrix = inv(matrix)
print(inv_matrix)
Drag options to blanks, or click blank then click option'
Ainverse
Binv_matrix
Cinvert
Dinv
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inverse' instead of 'inv'.
Trying to import a non-existing function like 'invert'.
2fill in blank
medium

Complete the code to create a 2x2 numpy array matrix.

SciPy
import numpy as np

matrix = np.array([1])
print(matrix)
Drag options to blanks, or click blank then click option'
A[[1, 3], [2, 4]]
B[1, 2, 3, 4]
C[[1, 2], [3, 4]]
D[[1, 2, 3], [4, 5, 6]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a flat list instead of nested lists.
Using wrong dimensions like 2x3.
3fill in blank
hard

Fix the error in the code to correctly calculate the inverse of the matrix.

SciPy
from scipy.linalg import inv
import numpy as np

matrix = np.array([[1, 2], [3, 4]])
inv_matrix = [1](matrix)
print(inv_matrix)
Drag options to blanks, or click blank then click option'
Ainv
Binv_matrix
Cinvert
Dinverse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inverse' or 'invert' which are not defined.
Trying to call the variable name as a function.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each element to its inverse value.

SciPy
matrix = [1, 2, 4, 5]
inverse_map = { [1]: 1/[2] for [1] in matrix }
print(inverse_map)
Drag options to blanks, or click blank then click option'
Ax
Bi
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names before colon and after 'for'.
Using variable names not defined in the comprehension.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each number to its inverse if the number is not zero.

SciPy
numbers = [1, 2, 0, 4]
inverse_dict = { [1]: 1/[2] for [3] in numbers if [2] != 0 }
print(inverse_dict)
Drag options to blanks, or click blank then click option'
Anum
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing NameError.
Not checking for zero before division.