Re: simple questions about matrices
- To: mathgroup at smc.vnet.net
- Subject: [mg26481] Re: [mg26472] simple questions about matrices
- From: BobHanlon at aol.com
- Date: Thu, 28 Dec 2000 02:52:21 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
mat = Array[a, {4, 3}]; To sum by row (Plus @@ #) & /@ mat To sum by column (Plus @@ #) & /@ Transpose[mat] To append a row anotherRow = Array[r, Dimensions[mat][[2]]]; Append[mat, anotherRow] To append a column anotherColumn = Array[c, Dimensions[mat][[1]]]; Transpose[Append[Transpose[mat], anotherColumn]] Combining these sumByColumn[mat_List /; ! VectorQ[mat]] := Append[mat, (Plus @@ #) & /@ Transpose[mat]]; sumByRow[mat_List /; ! VectorQ[mat]] := Transpose[Append[Transpose[mat], (Plus @@ #) & /@ mat]]; sumByRow[mat] sumByColumn[mat] Bob Hanlon In a message dated 12/22/00 11:19:56 PM, cropazo at vassar.edu writes: >(a) I have a (m,n) matrix a with integer entries. How can I construct >a separate list with the totals of adding the entries of either the >rows or columns? > >(b) How can I construct a (m+1,n) matrix where the new row's entries >are the sums of all numbers on each column? > >(c) In general, how can I attach additional columns (o rows) to an >existing matrix? >