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:
from scipy.linalg import inv
A = [[1, 2], [3, 4]]
A_inv = inv(A)
Ainv() requires a sparse matrix
BA must be a numpy array, not a list
CMissing import for numpy
Dinv() cannot invert 2x2 matrices
Step-by-Step Solution
Solution:
  1. Step 1: Check input type for inv()

    The inv() function expects a numpy array or matrix, not a plain Python list.
  2. Step 2: Identify correction

    Convert A to a numpy array using np.array(A) before calling inv().
  3. Final Answer:

    A must be a numpy array, not a list -> Option B
  4. Quick Check:

    Input type for inv() = numpy array [OK]
Quick Trick: Convert lists to numpy arrays before matrix ops [OK]
Common Mistakes:
MISTAKES
  • Passing lists directly
  • Assuming inv() needs sparse matrix
  • Ignoring numpy import

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes