[SciPy-dev] numpy.cumproduct()

Alan G Isaac aisaac at american.edu
Wed Jul 4 13:42:48 EDT 2007


On Wed, 04 Jul 2007, dmitrey apparently wrote:
> I started to modify the page, but I noticed that python cumsum, cumprod,
> diff behavior differs from MATLAB one.
> for example,

>>>> a
>>>> array([[1, 2],
>>>>        [3, 4],
>>>>        [5, 6]])
>>>> cumsum(a)
>>>> array([ 1,  3,  6, 10, 15, 21])

> octave> cumsum([1 2; 3 4; 5 6])
> ans =
>    1   2
>    4   6
>    9  12



That is just a matter of the axis argument:
>>> numpy.cumsum(a, axis=0)
array([[ 1,  2],
       [ 4,  6],
       [ 9, 12]])

Cheers,
Alan Isaac





More information about the SciPy-Dev mailing list