WeCodeAcademy

Running Totals and Differences

np.cumsum gives a running total; np.cumprod a running product. np.diff gives the change from each value to the next (one fewer value than you started with). Together they answer questions such as "how much did we save so far?" and "how much did it change each month?".

Examplepython
Open in editor »
Quick check

What does `np.diff([5, 8, 6])` give?

Your turn: write the code

Print the running total of the daily sales.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.