[Numpy-discussion] new question - summing a list of arrays

Charles R Harris charlesr.harris@gmail....
Tue Mar 18 10:25:57 CDT 2008

On Tue, Mar 18, 2008 at 9:12 AM, Chris Withers <chris@simplistix.co.uk>

> Hi All,
> Say I have an aribtary number of arrays:
> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])]
> How can I sum these all together?
> My only solution so far is this:
> sum = arrays[0]
> for a in arrays[1:]:
>   sum += a
> ...which is ugly :-S

Doesn't look too bad to me. Alternatively, you could stack them together in
one big array and sum on the first axis, which might look cooler but isn't
likely to be any faster.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080318/0542967a/attachment.html 

More information about the Numpy-discussion mailing list