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 lu
A = np.array([[4, 3], [6, 3]])
P, L, U = lu(A)
print(np.round(L @ U, 2))
A[[6. 3.] [4. 3.]]
B[[1. 0.] [0. 1.]]
C[[3. 4.] [3. 6.]]
D[[0. 1.] [1. 0.]]
Step-by-Step Solution
Solution:
  1. Step 1: Understand LU decomposition and reconstruction

    LU decomposition factors A into P, L, U such that P@A = L@U. Multiplying L and U reconstructs P@A, not A directly.
  2. Step 2: Check output of L@U

    Since P is a permutation matrix, L@U equals P@A. For this matrix, P swaps rows, so L@U equals the permuted A matrix, which is [[6,3],[4,3]].
  3. Final Answer:

    [[6. 3.] [4. 3.]] -> Option A
  4. Quick Check:

    L@U = P@A = permuted A matrix [OK]
Quick Trick: L times U equals permuted A matrix, not original A [OK]
Common Mistakes:
MISTAKES
  • Expecting L@U to equal A without permutation
  • Confusing permutation matrix effect
  • Rounding errors in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes