[SciPy-dev] numpy.cumproduct()

Alan G Isaac aisaac@american....
Wed Jul 4 12:42:48 CDT 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