Bird
0
0

Find the mistake in this code snippet:

medium📝 Debug Q7 of 15
NumPy - Creating Arrays
Find the mistake in this code snippet:
import numpy as np
arr = np.random.rand(3, 3)
print(arr.shape())
Aprint statement syntax is wrong
Bnp.random.rand cannot create 2D arrays
Carr is not defined
DUsing parentheses with shape attribute causes an error
Step-by-Step Solution
Solution:
  1. Step 1: Check usage of shape attribute

    shape is an attribute, not a method, so no parentheses allowed.
  2. Step 2: Identify error

    Calling arr.shape() causes TypeError: 'tuple' object is not callable.
  3. Final Answer:

    Using parentheses with shape attribute causes an error -> Option D
  4. Quick Check:

    shape is attribute, no parentheses [OK]
Quick Trick: Use arr.shape, not arr.shape() [OK]
Common Mistakes:
  • Calling shape as function
  • Wrong print syntax
  • Assuming arr undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes