Re: Re: Select Maximum Value
- To: mathgroup at smc.vnet.net
- Subject: [mg107990] Re: [mg107948] Re: Select Maximum Value
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Thu, 4 Mar 2010 05:31:34 -0500 (EST)
- References: <201003020836.DAA03985@smc.vnet.net> <hmj274$eeo$1@smc.vnet.net>
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@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 <graser at gmail.com> wrote:
> On Mar 2, 8:01 am, Patrick Scheibe <psche... at 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 function
> > > 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]}];
>
>
- References:
- Select Maximum Value
- From: graser <graser@gmail.com>
- Select Maximum Value