|
[Date Index]
[Thread Index]
[Author Index]
Re: Question about Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg106571] Re: Question about Mathematica
- From: "Peter.Pein" <petsie at dordos.net>
- Date: Sat, 16 Jan 2010 06:14:35 -0500 (EST)
- References: <hipld8$7po$1@smc.vnet.net>
- Reply-to: "Peter.Pein" <petsie at dordos.net>
"Dominic" <miliotodc at rtconline.com> schrieb im Newsbeitrag
news:hipld8$7po$1 at smc.vnet.net...
> 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
>
Hi Domonic,
test3 = Table[row[[Ordering[row[[All, 2]]][[1]]]], {row, #}] &
is the fastest solution I found so far.
The others have been
test1 = (Cases[#1, {_, Min[#1[[All, 2]]]}, 1, 1][[1]] &) /@ # &
and the slow
test2 = Fold[If[#2[[2]] < #1[[2]], #2, #1] &, {foo, Infinity}, #] & /@ # &
All three give the desired result for your example and with
bigdat = RandomInteger[{-9, 9}, {10^6, 10, 2}];
I get
In[12]:= Timing[result1=test1[bigdat];][[1]]
Out[12]= 19.406
In[13]:= Timing[result2=test2[bigdat];][[1]]
Out[13]= 46.738
In[14]:= Timing[result3=test3[bigdat];][[1]]
Out[14]= 8.112
In[15]:= SameQ[result1,result2,result3]
Out[15]= True
Peter
Prev by Date:
Re: Re: More /.{I->-1} craziness
Next by Date:
Re: Re: More /.{I->-1} craziness
Previous by thread:
Re: Question about Mathematica
Next by thread:
Re: Re: Question about Mathematica
|