Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
SciPy - Sparse Matrices (scipy.sparse)
Identify the error in the following code snippet:
from scipy.sparse import csc_matrix
import numpy as np
arr = np.array([[1, 0], [0, 2]])
csc = csc_matrix(arr)
print(csc.indeces)
Acsc_matrix cannot be created from a 2D array.
BMissing import for numpy.
CTypo in attribute name: should be 'indices' not 'indeces'.
Dprint statement syntax is incorrect.
Step-by-Step Solution
Solution:
  1. Step 1: Check attribute names of CSC matrix

    The correct attribute for row indices is indices, not indeces.
  2. Step 2: Verify other parts of code

    Array creation and import are correct; print syntax is valid.
  3. Final Answer:

    Typo in attribute name: should be 'indices' not 'indeces'. -> Option C
  4. Quick Check:

    Attribute names must be exact [OK]
Quick Trick: Check spelling of attribute names carefully [OK]
Common Mistakes:
MISTAKES
  • Misspelling 'indices' attribute
  • Assuming csc_matrix can't take 2D arrays
  • Incorrect print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes