Re: Need to Speed up Position[]
- To: mathgroup at smc.vnet.net
- Subject: [mg110704] Re: Need to Speed up Position[]
- From: Peter Pein <petsie at dordos.net>
- Date: Fri, 2 Jul 2010 07:28:27 -0400 (EDT)
- References: <i0i1kr$hq6$1@smc.vnet.net>
Am Fri, 2 Jul 2010 06:56:09 +0000 (UTC)
schrieb Peter Pein <petsie at dordos.net>:
> Am Thu, 1 Jul 2010 12:28:11 +0000 (UTC)
> schrieb Garapata <warsaw95826 at mypacks.net>:
>
...
> >
> > My problem =85. the Position[] runs very very slow (over 90 seconds
> > on a dual core iMac).
> >
> > All the code together:
> >
> > myIntersection = Intersection @@ (myList[[All, All, 5]]);
> > myPositions = Drop[(Position[data, #] & /@ myIntersection), None,
> > None, -1];
> > myOutput = Extract[myList, #] & /@ myPositions;
> >
> > So, does anyone know a way to speed up:
> >
> > myPositions = Drop[(Position[data, #] & /@ myIntersection), None,
> > None, -1]; ?
> >
...
> >
> > Not clear what to try.
> > Please advise.
> >
> > Thanks.
> >
>
> Hi,
>
...
> In[3]:=
> Timing[Dimensions[
> myOutput=Split[Sort[Cases[myList,{___,Alternatives@@myIntersection},{2}],Last[#1]<Last[#2]&],Last[#1]===Last[#2]&]
> ]]
> Out[3]= {11.28,{3126}}
> In[4]:= myOutput[[1]]
> Out[4]=
> {{3830,4047,4200,3520,1},{4788,4153,2710,2938,1},{886,2560,5266,128,1},{143,218,3189,3672,1},{190,510,4701,212,1}}
...
I've got an even faster one:
In[28]:=
Timing[Dimensions[myOutput3=Flatten[Reap[Map[Sow[#,Last[#]]&,myList,{2}],myIntersection][[2]],1]]]
Out[28]= {0.67,{3141}}
In[29]:= Take[myOutput3,2]
Out[29]=
{{{2761,725,4865,2720,1},{4797,142,1312,1205,1},{1599,1513,498,2462,1},{4839,3373,3734,2125,1},{5277,1388,5042,1560,1},{3108,4445,2094,834,1}},
{{3852,3620,4120,3374,2},{1528,4708,573,2008,2},{877,2578,4421,5013,2},{143,3997,762,3376,2},{4783,2438,1249,934,2},{3639,3493,1495,2255,2},
{2423,4824,2705,80,2},{5079,2757,5297,2897,2},{1265,2193,2395,1409,2}}
}
hth,
Peter