Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q7 of 15
NumPy - Fundamentals
Identify the error in this code snippet:
import numpy as np
arr = np.array([1, 2, 3])
print(arr.reshape(2, 2))
ASyntax error in reshape call
Breshape requires a tuple argument
CCannot reshape array of size 3 into shape (2, 2)
Darr is not a NumPy array
Step-by-Step Solution
Solution:
  1. Step 1: Check array size and reshape shape

    arr has 3 elements, but reshape tries to make shape (2, 2) which needs 4 elements.
  2. Step 2: Understand reshape constraints

    Reshape must keep total elements same; here 3 != 4, so error occurs.
  3. Final Answer:

    Cannot reshape array of size 3 into shape (2, 2) -> Option C
  4. Quick Check:

    Reshape size mismatch error = D [OK]
Quick Trick: Reshape total elements must match array size [OK]
Common Mistakes:
  • Ignoring total element count in reshape
  • Thinking reshape changes data size
  • Assuming reshape accepts separate arguments only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes