MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Performance of Array Addition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90952] Performance of Array Addition
  • From: Jeremy <jeremytfox at mac.com>
  • Date: Thu, 31 Jul 2008 02:57:38 -0400 (EDT)

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


  • Prev by Date: When is a List not a List?
  • Next by Date: Problem with evaluating Graphics3D output
  • Previous by thread: Re: When is a List not a List?
  • Next by thread: Problem with evaluating Graphics3D output