Bird
0
0

What is the output shape of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Array Manipulation
What is the output shape of the following code?
import numpy as np
arr = np.arange(12)
new_arr = arr.reshape(3, 4)
print(new_arr.shape)
A(3, 4)
B(4, 3)
C(12,)
D(2, 6)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the original array

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

    The reshape changes the array to 3 rows and 4 columns, so the shape becomes (3, 4).
  3. Final Answer:

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

    reshape(3,4) = (3,4) shape [OK]
Quick Trick: reshape dims become shape tuple [OK]
Common Mistakes:
  • Confusing rows and columns order
  • Thinking reshape changes total elements
  • Expecting original 1D shape after reshape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes