Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
NumPy - Creating Arrays
Identify the error in this code:
import numpy as np
arr = np.ones(3, 3)
print(arr)
AShape must be a single tuple, not two separate arguments
Bnp.ones() cannot create arrays of size 3
CMissing dtype argument causes error
Dnp.ones() requires a list, not integers
Step-by-Step Solution
Solution:
  1. Step 1: Check the function call syntax

    np.ones() expects the shape as a single argument, usually a tuple for multiple dimensions.
  2. Step 2: Identify the error

    Passing two separate integers 3, 3 is invalid; it should be np.ones((3, 3)).
  3. Final Answer:

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

    Shape argument must be a tuple for multi-D arrays [OK]
Quick Trick: Pass shape as one tuple, not separate numbers [OK]
Common Mistakes:
  • Passing multiple arguments instead of one tuple
  • Assuming dtype is mandatory
  • Using list instead of tuple (valid but less common)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes