Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
SciPy - Linear Algebra (scipy.linalg)
What is wrong with this code?
import numpy as np
from scipy.linalg import qr
A = np.array([[1, 2], [3, 4]])
Q, R = qr(A)
print(Q @ R)
Aqr returns only one matrix, not two
BNothing wrong; Q @ R equals A
CQ and R shapes do not match for multiplication
DQ and R are not multiplied correctly
Step-by-Step Solution
Solution:
  1. Step 1: Understand QR decomposition output

    qr(A) returns Q and R such that Q @ R reconstructs A.
  2. Step 2: Confirm matrix multiplication correctness

    Multiplying Q and R returns the original matrix A without error.
  3. Final Answer:

    Nothing wrong; Q @ R equals A -> Option B
  4. Quick Check:

    Q times R reconstructs A correctly [OK]
Quick Trick: Q @ R reconstructs original matrix A [OK]
Common Mistakes:
MISTAKES
  • Thinking Q @ R is invalid
  • Assuming qr returns one matrix
  • Confusing matrix multiplication order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes