0
0
NumPydata~15 mins

np.cumsum() for cumulative sum in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Calculate Cumulative Sum Using np.cumsum()
📖 Scenario: Imagine you have daily sales numbers for a small shop. You want to see how sales add up day by day to understand the total sales over time.
🎯 Goal: You will create a list of daily sales, then use np.cumsum() to find the running total of sales each day.
📋 What You'll Learn
Create a numpy array called daily_sales with exact values: 5, 10, 7, 3, 8
Create a variable called cumulative_sales that stores the cumulative sum of daily_sales using np.cumsum()
Print the cumulative_sales array
💡 Why This Matters
🌍 Real World
Cumulative sums are used in finance to track total earnings, in health to track total steps walked, and in sales to track total revenue over time.
💼 Career
Data analysts and scientists often use cumulative sums to understand trends and totals in datasets, making this a key skill for reporting and decision-making.
Progress0 / 4 steps
1
Create the daily sales data
Import numpy as np and create a numpy array called daily_sales with these exact values: 5, 10, 7, 3, 8
NumPy
Need a hint?

Use np.array() to create the array with the exact numbers inside square brackets.

2
Calculate cumulative sales
Create a variable called cumulative_sales and set it to the cumulative sum of daily_sales using np.cumsum()
NumPy
Need a hint?

Use np.cumsum() and pass daily_sales inside the parentheses.

3
Print the cumulative sales
Write a print statement to display the cumulative_sales array
NumPy
Need a hint?

Use print(cumulative_sales) to show the running totals.

4
Explain the result
Add a print statement that explains the output by printing: 'Cumulative sales show total sales up to each day.'
NumPy
Need a hint?

Use print() with the exact text inside quotes.