Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
SciPy - Sparse Matrices (scipy.sparse)
What is wrong with this code?
from scipy.sparse import csc_matrix
import numpy as np
arr = np.array([1, 0, 2])
csc = csc_matrix(arr)
print(csc.shape)
AInput array must be 2D, not 1D.
Bcsc_matrix does not have a shape attribute.
CMissing parentheses in print statement.
DCannot create CSC matrix from numpy array.
Step-by-Step Solution
Solution:
  1. Step 1: Check input array shape

    The input is a 1D array, but CSC matrix requires 2D input.
  2. Step 2: Confirm other code parts

    csc_matrix has a shape attribute; print syntax is correct.
  3. Final Answer:

    Input array must be 2D, not 1D. -> Option A
  4. Quick Check:

    CSC input must be 2D array [OK]
Quick Trick: CSC matrices need 2D arrays as input [OK]
Common Mistakes:
MISTAKES
  • Passing 1D array instead of 2D
  • Assuming shape attribute missing
  • Incorrect print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes