Re: Newbie question about column sums of arrays

*To*: mathgroup at smc.vnet.net*Subject*: [mg68535] Re: Newbie question about column sums of arrays*From*: Bill Rowe <readnewsciv at earthlink.net>*Date*: Wed, 9 Aug 2006 04:19:02 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

On 8/8/06 at 6:29 AM, gwgilc at wm.edu (George W. Gilchrist) wrote: >I have spent several hours trying to find an answer to what must be >an incredibly simple problem: how to sum the columns of an array >containing a random mix of +1 and -1s. For example: >In[7]:= AA1=Array[x, {4,4}]/. x:> (-1)^Random[Integer] Array isn't doing what you expect or want. Array expects a function as its first argument, not a number. So, what you get for the first term will either be 1[1,1] or -1[1,1] which in Mathematica syntax is the function 1 evaluated with arguments 1,1 clearly something that doesn't make sense. For generating a 2D random mix of 1 and -1 the simplest method is to use Table, i.e., Table[(-1)^Random[Integer],{4},{4}] However, if you did want to use Array it is possible to get what you want. For example, this would work Array[(-1)^Random[Integer] Times @@ Sign[{##}] &, {4, 4}] But this clearly has Mathematica do more work to get the same result. -- To reply via email subtract one hundred and four