0
0
SciPydata~20 mins

Matrix inverse (inv) in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matrix Inverse Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of matrix inverse calculation
What is the output of this code that calculates the inverse of a 2x2 matrix using scipy?
SciPy
import numpy as np
from scipy.linalg import inv

matrix = np.array([[4, 7], [2, 6]])
result = inv(matrix)
print(result)
A
[[ 1.5 -1.7]
 [-0.2  0.4]]
B
[[ 0.6 -0.7]
 [-0.2  0.4]]
C
[[ 0.6  0.7]
 [ 0.2  0.4]]
D
[[ 0.6 -0.7]
 [ 0.2 -0.4]]
Attempts:
2 left
💡 Hint
Recall the formula for inverse of 2x2 matrix [[a,b],[c,d]] is (1/(ad-bc))*[[d,-b],[-c,a]]
data_output
intermediate
1:30remaining
Number of elements in inverse matrix
After computing the inverse of a 3x3 matrix using scipy.linalg.inv, how many elements does the resulting matrix contain?
SciPy
import numpy as np
from scipy.linalg import inv

matrix = np.array([[1,2,3],[0,1,4],[5,6,0]])
inverse = inv(matrix)
print(inverse.size)
A9
B6
C3
D1
Attempts:
2 left
💡 Hint
The inverse matrix has the same shape as the original matrix.
🔧 Debug
advanced
2:00remaining
Error type when inverting a singular matrix
What error does this code raise when trying to invert a singular matrix using scipy.linalg.inv?
SciPy
import numpy as np
from scipy.linalg import inv

singular_matrix = np.array([[1, 2], [2, 4]])
inv(singular_matrix)
AIndexError: index out of bounds
BValueError: Input must be square
CLinAlgError: Singular matrix
DTypeError: Unsupported operand type(s)
Attempts:
2 left
💡 Hint
A singular matrix has zero determinant and cannot be inverted.
🧠 Conceptual
advanced
1:00remaining
Effect of matrix inverse on identity matrix
If you multiply a matrix by its inverse, what is the resulting matrix?
AA matrix with all elements equal to one
BA zero matrix
CThe original matrix squared
DThe identity matrix
Attempts:
2 left
💡 Hint
Think about what an inverse matrix means in multiplication.
🚀 Application
expert
2:30remaining
Using matrix inverse to solve linear equations
Given the system of equations represented by Ax = b, where A is a 2x2 matrix and b is a vector, which code correctly computes x using scipy.linalg.inv?
SciPy
import numpy as np
from scipy.linalg import inv

A = np.array([[3, 1], [1, 2]])
b = np.array([9, 8])
A
x = inv(A).dot(b)
print(x)
B
x = b.dot(inv(A))
print(x)
C
x = inv(b).dot(A)
print(x)
D
x = A.dot(inv(b))
print(x)
Attempts:
2 left
💡 Hint
Remember the formula x = A^-1 * b for solving Ax = b.