MathGroup Archive 2006

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

Search the Archive

Re: How Functions are Applied to Matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66090] Re: How Functions are Applied to Matrices
  • From: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>
  • Date: Sat, 29 Apr 2006 03:40:37 -0400 (EDT)
  • References: <e2ss22$457$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mean is behaving in the expected way. Each element of your list is itself a 
list, and the mean of these list-valued elements is being computed. In 
general, when using (most) Mathematica functions it is not useful to 
visualise expressions in terms of the special (row,column) formatting that 
is associated with "matrices". This is because the head of the various parts 
of the expression (which in your case is List) is usually some function 
other than List, for which the correspondence with matrices does not exist.

Your use of Map is the correct approach in this case.

Steve Luttrell

"Gregory Lypny" <gregory.lypny at videotron.ca> wrote in message 
news:e2ss22$457$1 at smc.vnet.net...
> 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.}
> 



  • Prev by Date: Re: help in solving a double integration....
  • Next by Date: Re: Illusory Multicore Support in 5.2?
  • Previous by thread: Re: How Functions are Applied to Matrices
  • Next by thread: TraditionalForm bug?