MathGroup Archive 2000

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

Search the Archive

Re: simple questions about matrices

  • To: mathgroup at
  • Subject: [mg26481] Re: [mg26472] simple questions about matrices
  • From: BobHanlon at
  • Date: Thu, 28 Dec 2000 02:52:21 -0500 (EST)
  • Sender: owner-wri-mathgroup at

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]];



Bob Hanlon

In a message dated 12/22/00 11:19:56 PM, cropazo at 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?

  • Prev by Date: Re: Infinite sum of n^2 Exp[-n^2]
  • Next by Date: RE: simple questions about matrices
  • Previous by thread: Re: simple questions about matrices
  • Next by thread: RE: simple questions about matrices