Bird
0
0

What is the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Aggregation Functions
What is the output of this code?
import numpy as np
arr = np.array([[2, 4], [6, 8]])
print(np.mean(arr, axis=0))
A[3. 5.]
B[4. 6.]
C[6. 8.]
D[2. 4.]
Step-by-Step Solution
Solution:
  1. Step 1: Understand axis=0

    Calculates mean down each column.
  2. Step 2: Calculate means

    Column 1: (2+6)/2 = 4, Column 2: (4+8)/2 = 6
  3. Final Answer:

    [4. 6.] -> Option B
  4. Quick Check:

    Mean per column calculated correctly [OK]
Quick Trick: Axis 0 averages columns [OK]
Common Mistakes:
  • Confusing axis=0 with axis=1
  • Calculating sum instead of mean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes