[Numpy-discussion] summing an array

Bob Dowling rjd4+numpy at cam.ac.uk
Fri Aug 19 12:14:15 EDT 2011


On 19/08/11 15:49, Chris Withers wrote:
> On 18/08/2011 07:58, Bob Dowling wrote:
>>
>> >>> numpy.add.accumulate(a)
>> array([ 0, 1, 3, 6, 10])
>>
>> >>> numpy.add.accumulate(a, out=a)
>> array([ 0, 1, 3, 6, 10])
>
> What's the difference between numpy.cumsum and numpy.add.accumulate?

I think they're equivalent, with numpy.cumprod() serving for 
numpy.multiply.accumulate()

I have a prefeence for general procedures rather than special short 
cuts.  The numpy.<ufunc>.accumulate works for any of the binary ufuncs I 
think.  The cumsum() and cumprod() functions only exist for add and 
multiply.

e.g.

 >>> a = numpy.arange(2,5)
 >>> a
array([2, 3, 4])
 >>> numpy.power.accumulate(a)
array([   2,    8, 4096])


> Where can I find the reference docs for these?

help(numpy.ufunc)
help(numpy.ufunc.accumulate)

is where I started.



More information about the NumPy-Discussion mailing list