0
0
NumPydata~10 mins

np.linalg.inv() for matrix inverse in NumPy - 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 numpy library with the common alias.

NumPy
import [1] as np
Drag options to blanks, or click blank then click option'
Anumpy
Bpandas
Cmatplotlib
Dscipy
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like pandas or matplotlib.
Not using the alias np.
2fill in blank
medium

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

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

Fix the error in the code to compute the inverse of the matrix.

NumPy
inverse = np.linalg.[1](matrix)
Drag options to blanks, or click blank then click option'
Aeig
Bdet
Csolve
Dinv
Attempts:
3 left
💡 Hint
Common Mistakes
Using det which computes determinant, not inverse.
Using solve which solves linear systems.
4fill in blank
hard

Fill both blanks to create a dictionary with keys as matrix elements and values as their inverses.

NumPy
inverse_dict = {element: [1] for row in matrix for element in row if element [2] 0}
Drag options to blanks, or click blank then click option'
A1/element
Belement
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality check instead of inequality in the condition.
Not handling zero elements causing division by zero.
5fill in blank
hard

Fill all three blanks to compute the inverse matrix and print it.

NumPy
import numpy as np
matrix = np.array([1])
inverse = np.linalg.[2](matrix)
print([3])
Drag options to blanks, or click blank then click option'
A[[2, 0], [0, 2]]
Binv
Cinverse
D[[1, 2], [3, 4]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong matrix shape.
Calling a wrong function instead of inv.
Printing the original matrix instead of the inverse.