Bird
0
0

What is the shape of the array after executing this code?

medium📝 Predict Output Q4 of 15
NumPy - Array Manipulation
What is the shape of the array after executing this code?
import numpy as np
arr = np.arange(12)
new_arr = arr.reshape(4, 3)
A(4, 3)
B(3, 4)
C(12, 1)
D(1, 12)
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.arange(12)

    This creates a 1D array with 12 elements from 0 to 11.
  2. Step 2: Reshape to (4, 3)

    The reshape changes the array to 4 rows and 3 columns.
  3. Final Answer:

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

    Reshape result shape = (4, 3) [OK]
Quick Trick: Reshape shape matches given dimensions [OK]
Common Mistakes:
  • Confusing rows and columns
  • Assuming original shape remains
  • Miscounting total elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes