Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: How Functions are Applied to Matrices

  • To: mathgroup at
  • Subject: [mg66086] Re: [mg66064] How Functions are Applied to Matrices
  • From: Andrzej Kozlowski <akoz at>
  • Date: Sat, 29 Apr 2006 03:40:25 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

On 28 Apr 2006, at 19:32, Gregory Lypny 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[[2]] 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[182]:=
> Mean[data[[2]]]//N
> Out[182]=
> 5.25
> Applying Mean to the whole matrix computes the mean of columns, not
> rows.
> In[181]:=
> Mean[data]//N
> Out[181]=
> {-4.33333,3.66667,-1.,4.33333}
> I need to Map it to have it applied to each list.
> In[183]:=
> Map[Mean,data]//N
> Out[183]=
> {0.75,5.25,-4.}

I am not sure if you will be satisfied with the following as the  
answer to the question "why?" but at least I can say that Mean  
inherits this behaviour from Total. Indeed, the Help for Mean says:

Mean[list] is equivalent to Total[list]/Length[list].

On the other hand,

mm = {{a, b, c}, {d, e, f}, {g, h, k}};



which is the same as



Why? Probably because this behaviour is often convenient.

Andrzej Kozlowski

  • Prev by Date: Re: How Functions are Applied to Matrices
  • Next by Date: Re: help in solving a double integration....
  • Previous by thread: How Functions are Applied to Matrices
  • Next by thread: Re: How Functions are Applied to Matrices