Bird
0
0

Why does this code raise an error?

medium📝 Debug Q7 of 15
NumPy - Creating Arrays
Why does this code raise an error?
import numpy as np
arr = np.empty()
Anp.empty() cannot create empty arrays
BMissing required shape argument
Cdtype argument is mandatory
DShape argument must be a list
Step-by-Step Solution
Solution:
  1. Step 1: Check np.empty() required parameters

    np.empty() requires a shape argument to allocate memory.
  2. Step 2: Identify cause of error

    Calling without shape causes a TypeError for missing required positional argument.
  3. Final Answer:

    Missing required shape argument -> Option B
  4. Quick Check:

    Shape argument is mandatory for np.empty() [OK]
Quick Trick: Always provide shape argument to np.empty() [OK]
Common Mistakes:
  • Calling np.empty() without shape
  • Thinking dtype is mandatory
  • Passing shape as list instead of tuple

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes