Bird
0
0

Which of the following best describes the effect of np.cumsum() on a 2D numpy array without specifying an axis?

easy📝 Conceptual Q2 of 15
NumPy - Aggregation Functions
Which of the following best describes the effect of np.cumsum() on a 2D numpy array without specifying an axis?
ARaises an error due to missing axis
BComputes cumulative sum row-wise
CComputes cumulative sum column-wise
DComputes cumulative sum over the flattened array
Step-by-Step Solution
Solution:
  1. Step 1: Check default behavior of np.cumsum()

    When axis is not specified, numpy flattens the array before operation.
  2. Step 2: Understand cumulative sum on flattened array

    The function sums elements in the flattened order, returning a 1D array of cumulative sums.
  3. Final Answer:

    Computes cumulative sum over the flattened array -> Option D
  4. Quick Check:

    Default axis = flattened array cumulative sum [OK]
Quick Trick: No axis means flatten first, then sum [OK]
Common Mistakes:
  • Assuming row-wise sum by default
  • Expecting column-wise sum without axis
  • Thinking it raises an error without axis

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes