Re: Newbie question about column sums of arrays
- To: mathgroup at smc.vnet.net
- Subject: [mg68547] Re: [mg68508] Newbie question about column sums of arrays
- From: "Bharat Bhole" <bbhole at gmail.com>
- Date: Wed, 9 Aug 2006 04:20:08 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
AA1 consists of elements of the form x[1,1],x[1,2],....,x[3,2]... etc. Your replacement rule is just replacing the letter x in these expressions keeping the other part the same. That is, you get elements like 1[1,1], -1[1,2],-1[1,3] etc. This explains why the sum is not given as numbers..you are not summing numbers. Hopefully someone else will write how to use replacement rule in such a case (I am curious to know too). Meanwhile the following will give you the desired result. In1: AA1=Table[(-1)^Random[Integer],{i,1,4},{j,1,4}] In2: Total[AA1] Bharat. On 8/8/06, George W. Gilchrist <gwgilc at wm.edu> 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] > > > Out[7]= > \!\(\*FormBox[ > RowBox[{"(", "\[NoBreak]", GridBox[{ > {\(1[1, 1]\), \(1[1, 2]\), \(\((\(-1\))\)[1, 3]\), \(1[1, 4] > \)}, > {\(1[2, 1]\), \(1[2, 2]\), \(\((\(-1\))\)[ > 2, 3]\), \(\((\(-1\))\)[2, 4]\)}, > {\(1[3, 1]\), \(\((\(-1\))\)[3, 2]\), \(1[3, 3]\), \(1[3, 4] > \)}, > {\(\((\(-1\))\)[4, 1]\), \(1[4, > 2]\), \(1[4, 3]\), \(\((\(-1\))\)[4, 4]\)} > }, > RowSpacings->1, > ColumnSpacings->1, > ColumnAlignments->{Left}], "\[NoBreak]", ")"}], > TraditionalForm]\) > > In[8]:= > Total[AA1] > > Out[8]= > {(-1)[4,1]+1[1,1]+1[2,1]+1[3,1], > (-1)[3,2]+1[1,2]+1[2,2]+1[4,2], > (-1)[1,3]+(-1)[2,3]+1[3,3]+1[4,3], > (-1)[2,4]+(-1)[4,4]+1[1,4]+1[3,4]} > > > So, Total[] seems to do the right thing, but I cannot get the actual > sums as real numbers, only this rather verbose representation. I have > searched the manuals for just about everything I can think of with no > luck. So, thanks for any help you can give me. > > > Cheers, George > > .................................................................. > George W. Gilchrist Email #1: gwgilc at wm.edu > Department of Biology, Box 8795 Email #2: kitesci at cox.net > College of William & Mary Phone: (757) 221-7751 > Williamsburg, VA 23187-8795 Fax: (757) 221-6483 > http://gwgilc.people.wm.edu/ > > > -- ---------------------------------------------------------- "No problem can withstand the assault of sustained thinking." Voltaire ----------------------------------------------------------