[Numpy-discussion] Sum over array elements

Patrick Marsh patrickmarshwx@gmail....
Mon Apr 12 09:29:51 CDT 2010


a = np.arange(10)
b = (a[::2]).sum()


Patrick




On Mon, Apr 12, 2010 at 9:21 AM, Nicola Creati <ncreati@inogs.it> wrote:

> 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
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Patrick Marsh
Ph.D. Student / NSSL Liaison to the HWT
School of Meteorology / University of Oklahoma
Cooperative Institute for Mesoscale Meteorological Studies
National Severe Storms Laboratory
http://www.patricktmarsh.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100412/9c6b1eb4/attachment.html 


More information about the NumPy-Discussion mailing list