Bird
0
0

What will be the shape of the array created by this code?

medium📝 Predict Output Q5 of 15
NumPy - Creating Arrays
What will be the shape of the array created by this code?
import numpy as np
arr = np.empty(5)
AError: shape must be tuple
B(5,)
C(5, 1)
D(1, 5)
Step-by-Step Solution
Solution:
  1. Step 1: Understand shape argument

    Passing an integer 5 creates a 1D array with 5 elements, shape (5,).
  2. Step 2: Confirm no error occurs

    Passing an int is valid for 1D arrays; no error is raised.
  3. Final Answer:

    (5,) -> Option B
  4. Quick Check:

    Integer shape creates 1D array (5,) [OK]
Quick Trick: Integer shape means 1D array with that length [OK]
Common Mistakes:
  • Expecting 2D shape
  • Thinking error occurs
  • Confusing (5,) with (1,5)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes