[Numpy-discussion] Sum over array elements

Nicola Creati ncreati at inogs.it
Mon Apr 12 10:21:45 EDT 2010


Hello,
I want to calculate, given a one dimension array, the sum over every two 
elements of the array.
I found this working solution:

a = N.arange(10)
b = a.reshape(a, (5, 2))
c = b.sum(axis=1)

Is there any better solution?

Thanks,

Nicola Creati




More information about the NumPy-Discussion mailing list