Skip to content
Justice Tech School

Cumulative Operations

cumsum, cumprod and diff track running totals and changes.

Example
a = np.array([1, 2, 3, 4])
print(np.cumsum(a), np.cumprod(a), np.diff(a))

Result

[ 1  3  6 10] [ 1  2  6 24] [1 1 1]

Exercise

Running total.

np.(a)

Quiz Test

What does diff give?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.