Bird
0
0

Given the array:

medium📝 Predict Output Q13 of 15
NumPy - Aggregation Functions
Given the array:
arr = np.array([[1, 2, 3], [4, 5, 6]])

What is the output of np.sum(arr, axis=0)?
A[3 7 11]
B[5 7 9]
C[6 15]
D[1 2 3 4 5 6]
Step-by-Step Solution
Solution:
  1. Step 1: Understand axis=0 sum

    Sum down rows means add elements in each column: (1+4), (2+5), (3+6).
  2. Step 2: Calculate sums

    Calculations: 1+4=5, 2+5=7, 3+6=9, so result is [5 7 9].
  3. Final Answer:

    [5 7 9] -> Option B
  4. Quick Check:

    Sum axis=0 adds columns down rows [OK]
Quick Trick: Sum axis=0 adds columns down rows [OK]
Common Mistakes:
  • Adding rows instead of columns
  • Confusing axis=0 with axis=1
  • Returning flattened array instead of summed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes