Bird
0
0

Given the array:

medium📝 Predict Output Q4 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[6 8]
B[3 7]
C[1 2 3]
D[9 12]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the array shape and axis

    The array shape is (3, 2). Axis=0 means sum down rows for each column.
  2. Step 2: Calculate sum along axis=0

    Sum column 1: 1 + 3 + 5 = 9
    Sum column 2: 2 + 4 + 6 = 12
  3. Final Answer:

    [9 12] is the sum along columns -> Option D
  4. Quick Check:

    Sum axis=0 = column sums = [9 12] [OK]
Quick Trick: axis=0 sums columns, add down rows [OK]
Common Mistakes:
  • Summing rows instead of columns
  • Mixing up axis=0 and axis=1
  • Incorrect addition of elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes