Bird
0
0

What will be the output shape of this code?

medium📝 Predict Output Q5 of 15
NumPy - Creating Arrays
What will be the output shape of this code?
import numpy as np
arr = np.random.rand(2, 2, 2)
A(2, 2, 2)
B(8,)
C(2, 4)
D(4, 2)
Step-by-Step Solution
Solution:
  1. Step 1: Analyze np.random.rand arguments

    Arguments (2, 2, 2) create a 3D array with shape 2x2x2.
  2. Step 2: Confirm output shape

    The resulting array shape is exactly (2, 2, 2).
  3. Final Answer:

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

    Shape matches 3D input args [OK]
Quick Trick: np.random.rand dims = output shape directly [OK]
Common Mistakes:
  • Flattening to 1D
  • Mixing dimension order
  • Summing dimensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes