From: Raffy on
On Mar 4, 2:31 am, Leonid Shifrin <lsh...(a)gmail.com> wrote:
> Hi,
>
> You can not use Max as easily as before for your new formulation.
>
> Assuming this is your array:
>
> In[18]:= a = {{{1, 2}, {2, 1}, {3, 4}}, {{1, 5}, {2, 1}, {3, 2}}}
>
> Out[18]= {{{1, 2}, {2, 1}, {3, 4}}, {{1, 5}, {2, 1}, {3, 2}}}
>
> Here are a couple of ways:
>
> In[19]:= Module[{max},
> Fold[If[#1[[2]] < #2[[2]], max = #2, max] &, max = First@#,
> Rest@#] & /@ a]
>
> Out[19]= {{3, 4}, {1, 5}}
>
> In[20]:= Extract[#,
> First(a)Position[#, {_, Max[#[[All, 2]]]}, 1, 1]] & /@ a
>
> Out[20]= {{3, 4}, {1, 5}}
>
> Regards,
> Leonid
>
>
>
> On Wed, Mar 3, 2010 at 1:54 PM, graser <gra...(a)gmail.com> wrote:
> > On Mar 2, 8:01 am, Patrick Scheibe <psche...(a)trm.uni-leipzig.de>
> > wrote:
> > > Hi,
>
> > > it is simply
>
> > > A = {{2, 4, 1, 3, 2, 2}, {4, 7, 9, 1, 2, 4}};
>
> > > Max /@ A
>
> > > and your code is not working at all.
>
> > > Cheers
> > > Patrick
>
> > > Am Mar 2, 2010 um 9:36 AM schrieb graser:
>
> > > > Hi
>
> > > > I want to pick up the maximum value of each list in the Array
>
> > > > A={{2, 4, 1, 3, 2, 2}, {4,7,9,1,2,4}}
>
> > > > I can do it in two steps..
>
> > > > B=Table[Sort[A[[i]], #1>#2&], {i, 1, Length[A]}];
>
> > > > C=Table[B[i], {i, 1, Length[B]}];
>
> > > > But is there any way I can do it in just one step with Select funct=
ion
> > > > or any thing else?
>
> > > > Thanks
>
> > Thanks for all of your comments..
>
> > Here I have more question for you..
>
> > If Array has
>
> > A={{1,2},{2,1},{3,4}},{{1,5},{2,1},{3,2}}..
>
> > Then If I want to pick up the list which has maximum value in second
> > column, So my result should be {{3,4},{1,5}}, can I still use the Max?
>
> > It just give the maximum value in first column like {4,5}
>
> > Or I have to use the multiple steps like
>
> > B = Table[Sort[A[[i]], #1[[2]] > #2[[2]] &], {i, 1, Length[A]}];
> > CD = Table[B[[i, 1]], {i, 1, Length[B]}];

I'd recommend: #[[First(a)Ordering[#[[All, 2]], -1]]] & /@ m