Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q4 of 15
NumPy - Creating Arrays
What will be the output of the following code?
import numpy as np
arr = np.zeros((2,3))
print(arr.shape)
A(2, 3)
B(3, 2)
C[2, 3]
D6
Step-by-Step Solution
Solution:
  1. Step 1: Understand the shape parameter

    The array is created with shape (2, 3), meaning 2 rows and 3 columns.
  2. Step 2: Check the output of arr.shape

    The shape attribute returns a tuple representing the dimensions, so it will be (2, 3).
  3. Final Answer:

    (2, 3) -> Option A
  4. Quick Check:

    arr.shape returns tuple of dimensions [OK]
Quick Trick: arr.shape returns tuple of array dimensions [OK]
Common Mistakes:
  • Confusing shape with size
  • Expecting list instead of tuple
  • Mixing row and column order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes