Bird
0
0

What is the output of this code?

medium📝 Predict Output Q4 of 15
SciPy - Linear Algebra (scipy.linalg)
What is the output of this code?
import numpy as np
from scipy.linalg import inv
matrix = np.array([[1, 2], [3, 4]])
inverse = inv(matrix)
print(np.round(inverse, 2))
A[[4.0 -2.0] [-3.0 1.0]]
B[[1.0 0.0] [0.0 1.0]]
C[[0.5 -0.5] [-1.5 2.0]]
D[[-2.0 1.0] [1.5 -0.5]]
Step-by-Step Solution
Solution:
  1. Step 1: Calculate the inverse of the matrix manually

    Matrix = [[1,2],[3,4]]; determinant = 1*4 - 2*3 = -2; inverse = (1/det)*[[4,-2],[-3,1]] = [[-2,1],[1.5,-0.5]]
  2. Step 2: Compare with printed rounded output

    Rounded to 2 decimals, inverse matches [[-2.0 1.0] [1.5 -0.5]].
  3. Final Answer:

    [[-2.0 1.0]\n [1.5 -0.5]] -> Option D
  4. Quick Check:

    Inverse calculation = Correct matrix inverse [OK]
Quick Trick: Inverse formula: 1/det * swap and negate elements [OK]
Common Mistakes:
MISTAKES
  • Ignoring determinant sign
  • Mixing up matrix elements
  • Not rounding output correctly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes