Complete the code to import the function that calculates the inverse of a matrix.
from scipy.linalg import [1] matrix = [[1, 2], [3, 4]] inv_matrix = inv(matrix) print(inv_matrix)
The function to calculate the inverse of a matrix in scipy.linalg is inv.
Complete the code to create a 2x2 numpy array matrix.
import numpy as np matrix = np.array([1]) print(matrix)
A 2x2 matrix is a list of two lists, each with two elements, like [[1, 2], [3, 4]].
Fix the error in the code to correctly calculate the inverse of the matrix.
from scipy.linalg import inv import numpy as np matrix = np.array([[1, 2], [3, 4]]) inv_matrix = [1](matrix) print(inv_matrix)
The correct function to calculate the inverse is inv, not 'inverse' or 'invert'.
Fill both blanks to create a dictionary comprehension that maps each element to its inverse value.
matrix = [1, 2, 4, 5] inverse_map = { [1]: 1/[2] for [1] in matrix } print(inverse_map)
In dictionary comprehension, the variable name before the colon and after 'for' must be the same. Here, 'x' is used consistently.
Fill all three blanks to create a dictionary comprehension that maps each number to its inverse if the number is not zero.
numbers = [1, 2, 0, 4] inverse_dict = { [1]: 1/[2] for [3] in numbers if [2] != 0 } print(inverse_dict)
Use the same variable name 'num' consistently in the comprehension for clarity and correctness.