Re: Performance of Array Addition
- To: mathgroup at smc.vnet.net
- Subject: [mg91022] Re: [mg90952] Performance of Array Addition
- From: Carl Woll <carlw at wolfram.com>
- Date: Mon, 4 Aug 2008 03:21:10 -0400 (EDT)
- References: <200807310657.CAA07753@smc.vnet.net>
Jeremy wrote:
>Let there be, for example, an array of reals with dimensions
>{d1,d2,3}.
>
>I have noticed that the command
>
>array[[All,All,1]] + array[[All,All,2]] + array[[All,All,3]];
>
>is much faster than
>
>Map[Total, array, {2}];
>
>even though they return the same answer.
>
>The advantage of Map[Total, array, {2}] is that it allows arrays of
>dimension {d1,d2,d3}, with d3 arbitrary.
>
>Is there a way to get closer to the speed advantages of hand-coding
>the addition of the final dimension, while
>allowing the number of elements in the final dimension to be
>arbitrary?
>
>Thanks, Jeremy
>
>
Why not
Total[array, {3}]
?
Carl Woll
Wolfram Research