       Re: How Functions are Applied to Matrices

• To: mathgroup at smc.vnet.net
• Subject: [mg66096] Re: [mg66064] How Functions are Applied to Matrices
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sat, 29 Apr 2006 03:40:52 -0400 (EDT)
• Reply-to: hanlonr at cox.net
• Sender: owner-wri-mathgroup at wolfram.com

```m=Array[a,{3,4}];

Mean takes each row of the array as a single element of the outer list to be averaged.

Mean[m]==(m[]+m[]+m[])/3

True

Bob Hanlon

---- Gregory Lypny <gregory.lypny at videotron.ca> wrote:
> Hello everyone,
>
> If I use functions, such as Mean, StandardDeviation, or Total, that
> operate on lists, they work the way I expect when applied to a single
> list.  So, for example, the mean of data[] below is 5.25.
> However, when I apply Mean to the entire 3 x 4 matrix, which I
> understand to be three lists, I expect to get three means.  Instead I
> get four because Mean is operating on the columns and not the rows,
> that is, the four corresponding elements of each of the three lists.
>
> Why is that?
>
> 	Greg
>
>
> data={{-9,8,3,1},{2,12,3,4},{-6,-9,-9,8}}
>
> The mean of the second list:
>
> In:=
> Mean[data[]]//N
>
> Out=
> 5.25
>
> Applying Mean to the whole matrix computes the mean of columns, not
> rows.
>
> In:=
> Mean[data]//N
>
> Out=
> {-4.33333,3.66667,-1.,4.33333}
>
> I need to Map it to have it applied to each list.
>
> In:=
> Map[Mean,data]//N
>
> Out=
> {0.75,5.25,-4.}
>

```

• Prev by Date: Re: Printing Lists to file without {}
• Next by Date: Re: Image Processing
• Previous by thread: Re: How Functions are Applied to Matrices
• Next by thread: Re: How Functions are Applied to Matrices