First page Back Continue Last page Overview Graphics

Reductions

>>> x = np.arange(9)

>>> x

array([0, 1, 2, 3, 4, 5, 6, 7, 8])

>>> np.sum(x)

36

>>> x = x.reshape(3,3)

>>> np.sum(x)

36

>>> x

array([[0, 1, 2],

[3, 4, 5],

[6, 7, 8]])

>>> x.sum(axis=0)

array([ 9, 12, 15])

>>> x.sum(axis=1)

array([ 3, 12, 21])

Exercise:

Test the result of cumsum!