Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
NumPy - Creating Arrays
Identify the error in this code snippet:
import numpy as np
arr = np.empty(3, 4)
print(arr)
Anp.empty() does not accept integers
BShape argument must be a single tuple, not two separate arguments
CMissing import statement
Dprint() cannot print numpy arrays
Step-by-Step Solution
Solution:
  1. Step 1: Check np.empty() argument format

    np.empty() expects one argument for shape, which should be a tuple like (3, 4).
  2. Step 2: Identify error in code

    The code passes two separate arguments 3, 4 instead of a tuple, causing a TypeError.
  3. Final Answer:

    Shape argument must be a single tuple, not two separate arguments -> Option B
  4. Quick Check:

    Shape must be tuple in np.empty() [OK]
Quick Trick: Pass shape as one tuple, e.g. (3,4) [OK]
Common Mistakes:
  • Passing multiple integers instead of a tuple
  • Forgetting to import numpy
  • Thinking print() can't show arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes