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

Alan G Isaac aisaac@american....
Tue Mar 18 10:23:06 CDT 2008

On Tue, 18 Mar 2008, Chris Withers apparently wrote:
> 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? 

Try N.sum(arrays,axis=0).

But must they be in a list?
An array of arrays (i.e., 2d array) is easy to sum.

> My only solution so far is this:
> sum = arrays[0] 
> for a in arrays[1:]:
>    sum += a
> ...which is ugly :-S 

And changes the first array!

Alan Isaac

More information about the Numpy-discussion mailing list