Cumulative sum of a NumPy array
Calculate the cumulative sum of a NumPy array.
Sample Solution:
Python Code:
Output:
[1 3 6 2 7]
Explanation:
Here's a breakdown of the above code:
- First we create a sample NumPy array "nums".
- The np.cumsum(nums) function calculates the cumulative sum of the elements in the array.
- The resulting "cumulative_sum" is a NumPy array containing the cumulative sums.
- The result is printed, showing the cumulative sum of the array.
Flowchart:

Python Code Editor:
Previous: Matrix Multiplication with NumPy.
Next: Generating and identifying unique values in a NumPy array.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.