Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
SciPy - Linear Algebra (scipy.linalg)
Identify the error in this code snippet:
import numpy as np
from scipy.linalg import cholesky
A = np.array([[4, 1], [1, 3]])
L = cholesky(A, lower=False)
print(L)
ANo error; code runs correctly
BUsing lower=False returns upper triangular matrix, not lower
CMatrix A is not positive definite
DMissing import for numpy
Step-by-Step Solution
Solution:
  1. Step 1: Check matrix properties

    Matrix A is symmetric and positive definite, so decomposition is valid.
  2. Step 2: Understand lower parameter

    Setting lower=False returns the upper triangular matrix U such that A = U.T * U, which is valid usage.
  3. Final Answer:

    No error; code runs correctly -> Option A
  4. Quick Check:

    lower=False returns upper triangular matrix [OK]
Quick Trick: lower=False returns upper triangular matrix [OK]
Common Mistakes:
MISTAKES
  • Thinking lower=False causes error
  • Assuming matrix not positive definite
  • Forgetting numpy import

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes