Bird
0
0

If you have a 2D array arr with shape (3, 4), what will be the shape of the result after applying np.mean(arr, axis=1)?

easy📝 Conceptual Q2 of 15
NumPy - Aggregation Functions
If you have a 2D array arr with shape (3, 4), what will be the shape of the result after applying np.mean(arr, axis=1)?
A(3,)
B(4,)
C()
D(3, 4)
Step-by-Step Solution
Solution:
  1. Step 1: Identify the shape of the original array

    The array has 3 rows and 4 columns, shape (3, 4).
  2. Step 2: Understand what axis=1 means for aggregation

    Axis=1 means aggregation happens across columns for each row, so each row reduces to a single value.
  3. Final Answer:

    The result shape is (3,) because each of the 3 rows becomes one mean value -> Option A
  4. Quick Check:

    axis=1 reduces columns, output shape = (3,) [OK]
Quick Trick: axis=1 aggregates across columns, output shape matches rows [OK]
Common Mistakes:
  • Confusing axis=1 with axis=0
  • Expecting 2D output instead of 1D
  • Assuming shape remains unchanged

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes