Bird
0
0

If you have a 2D array arr with shape (3, 4), what does np.sum(arr, axis=0) compute?

easy📝 Conceptual Q2 of 15
NumPy - Aggregation Functions
If you have a 2D array arr with shape (3, 4), what does np.sum(arr, axis=0) compute?
ASum of each row, resulting in an array of length 3.
BSum of each column, resulting in an array of length 4.
CSum of all elements, resulting in a scalar.
DSum of diagonal elements only.
Step-by-Step Solution
Solution:
  1. Step 1: Identify axis=0 meaning

    Axis 0 means summing down the rows, so we sum elements column-wise.
  2. Step 2: Result shape

    Since there are 4 columns, the result is an array of length 4 with sums of each column.
  3. Final Answer:

    Sum of each column, resulting in an array of length 4. -> Option B
  4. Quick Check:

    axis=0 sums columns = array length 4 [OK]
Quick Trick: axis=0 sums down rows (columns summed) [OK]
Common Mistakes:
  • Confusing axis=0 with axis=1
  • Expecting scalar output
  • Thinking it sums rows instead of columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes