MathGroup Archive 2008

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

Search the Archive

Re: Need help to find position of max location

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86577] Re: [mg86525] Need help to find position of max location
  • From: Curtis Osterhoudt <cfo at lanl.gov>
  • Date: Thu, 13 Mar 2008 20:55:15 -0500 (EST)
  • Organization: LANL
  • References: <200803130930.EAA01422@smc.vnet.net>
  • Reply-to: cfo at lanl.gov

In[37]:= t = {{82, 71, 62, 47}, {52, 96, 31, 36}, {94, 52, 86, 12}}

Out[37]= {{82, 71, 62, 47}, {52, 96, 31, 36}, {94, 52, 86, 12}}

In[38]:= Flatten[(Position[#1, Max[#1]] & ) /@ t]

Out[38]= {1, 2, 1}

    With your max = Map[Max, t] formulation, you may use something like the 
following:

   In[41]:= With[{maxes = Max /@ t}, 
 Flatten[(Position[t[[#1]], maxes[[#1]]] & ) /@ 
       Range[Length[maxes]]]]

Out[41]= {1, 2, 1}

          Hope that helps!
                       C.O.




On Thursday 13 March 2008 03:30:59 haitomi wrote:
> Hi All,
>
> I would like to find position of this problem
>
> Write a function that returns a list that gives the column location of the
> largest integer in each row of a matrix (a list of lists) of random
> integers between 30 and 99.
>
> Example, for the following 3 X 4 matrix the result is
>
> {1,2,1}
>
> {
>  {82, 71, 62, 47},
>  {52, 96, 31, 36},
>  {94, 52, 86, 12},
>
> }
>
> t=Table[RandomInteger[{30,99}],{i,1,3},{j,1,4}]
>
> max=Map[Max,t]
>
> and I stuck at Position of each Row, if someone can help me.
>
> Thanks



-- 
==========================================================
Curtis Osterhoudt
cfo at remove_this.lanl.and_this.gov
PGP Key ID: 0x4DCA2A10
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================


  • Prev by Date: Re: Need help to find position of max location
  • Next by Date: Re: V.6.0.2 gripes...
  • Previous by thread: Re: Need help to find position of max location
  • Next by thread: Re: Need help to find position of max location