[Tutor] summing arrays, along a dimension

bob gailer bgailer at alum.rpi.edu
Sat Sep 15 04:00:34 CEST 2007


John wrote:
> >>> d
> array([[0, 0, 1],
>        [1, 2, 3],
>        [2, 2, 4],
>        [3, 6, 8]])
> >>> e=reshape((d[:,-2]+d[:,-1]),(4,1))
> >>> e
> array([[ 1],
>        [ 5],
>        [ 6],
>        [14]])
>  
> is there a better way to accomplish this?
Which module are you using?

In APL we'd write +/d to reduce along the rows using +. Does the array 
object have a similar "reduce" method?



More information about the Tutor mailing list