Bird
0
0

Which of the following is the correct syntax to compute the cumulative sum of a numpy array arr?

easy📝 Conceptual Q12 of 15
NumPy - Aggregation Functions
Which of the following is the correct syntax to compute the cumulative sum of a numpy array arr?
Anp.cumsum(arr)
BAll of the above
Cnp.cumsum(arr, axis=0)
Darr.cumsum()
Step-by-Step Solution
Solution:
  1. Step 1: Check numpy function usage

    np.cumsum(arr) is the basic syntax to get cumulative sum of all elements in the array.
  2. Step 2: Check array method and axis parameter

    arr.cumsum() is a valid method call on numpy arrays. Also, np.cumsum(arr, axis=0) computes cumulative sum along the first axis, valid for multi-dimensional arrays.
  3. Final Answer:

    np.cumsum(arr) -> Option A
  4. Quick Check:

    Basic syntax is np.cumsum(arr) [OK]
Quick Trick: np and array method both work; axis optional [OK]
Common Mistakes:
  • Thinking only np.cumsum(arr) works
  • Ignoring axis parameter for multi-dimensional arrays
  • Assuming cumsum is not an array method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes