Bird
0
0

What error will occur when running this code?

medium📝 Debug Q14 of 15
NumPy - Array Manipulation
What error will occur when running this code?
import numpy as np
arr = np.arange(10)
new_arr = arr.reshape(3, 4)
AValueError: cannot reshape array of size 10 into shape (3,4)
BTypeError: reshape() takes exactly 1 argument
CSyntaxError: invalid syntax
DNo error, reshaping works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check original array size

    np.arange(10) creates an array with 10 elements.
  2. Step 2: Check reshape dimensions

    Trying to reshape into (3, 4) means 12 elements needed, but only 10 exist.
  3. Step 3: Identify error type

    This mismatch causes a ValueError about incompatible shape.
  4. Final Answer:

    ValueError: cannot reshape array of size 10 into shape (3,4) -> Option A
  5. Quick Check:

    Elements must match for reshape [OK]
Quick Trick: Total elements must match for reshape [OK]
Common Mistakes:
  • Ignoring total element count mismatch
  • Expecting reshape to auto-fill missing elements
  • Confusing ValueError with SyntaxError

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes