Name

accumulate

Synopsis

                        u.accumulate(a,axis=0)

Returns an array r with the same shape and type code as a. Each element of r is the accumulation of elements of a along the given axis with the function or operator underlying u. For example:

print add.accumulate(range(10))      
# prints: [0 1 3 6 10 15 21 28 36 45]

Since add’s underlying operator is +, and a is sequence 0,1,2,...,9, r is 0,0+1,0+1+2,...,0+1+...+8+9. In other words, r [0] is a [0], r [1] is r [0] + a [1], r [2] is r [1] + a [2], and so on (i.e., each r [ i ] is r [ i -1] + a [ i ]).

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.