Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Question about Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106547] Re: [mg106544] Question about Mathematica
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sat, 16 Jan 2010 06:09:54 -0500 (EST)
  • References: <201001151200.HAA07995@smc.vnet.net>

Hi Dominic,

here is your data:

data = {{{1, 2}, {3, -1}, {2, -4}}, {{1,
     2}, {4, -5}, {6, -8}}, {{2, -1}, {-2, -3}, {-4, 6}}};

Here is one way:

In[2]:=
Flatten[Extract[#, Position[#, Min[#], 1, 1] &[#[[All, 2]]]] & /@ data, 1]

Out[2]= {{2, -4}, {6, -8}, {-2, -3}}

Here is another one:

In[3]:= Map[SortBy[#, Last] &, data][[All, 1]]

Out[3]= {{2, -4}, {6, -8}, {-2, -3}}

This one is shorter but the first one is faster for larger lists. Since
there may be many sublists with the same minimal second element, the two
methods will not necessarily give identical results.

Regards,
Leonid


On Fri, Jan 15, 2010 at 3:00 PM, Dominic <miliotodc at rtconline.com> wrote:

> Hi.  Can someone help me with the following question:
>
> I have a table of a table of number pairs:
>
> {{{1,2),(3,-1),{2,-4)},{{1,2},{4,-5},{6,-8}},{{2,-1},{-2,-3},{-4,6}}}
>
> How may I find the minimum second element in each sub-table?  For
> example, the first sub-table is:
>
> {{1,2},{3,-1},{2,-4}}
>
> I would like to then extract the {2,-4} element from this item.  Then
> the {6,-8} from the second sub-table, then the {-2,-3} element from the
> last.
>
> Thank you,
> Dominic
>
>
>


  • Prev by Date: Re: Question about Mathematica
  • Next by Date: Re: More /.{I->-1} craziness
  • Previous by thread: Re: Question about Mathematica
  • Next by thread: Re: Question about Mathematica