Re: element selection
- To: mathgroup at smc.vnet.net
- Subject: [mg53630] Re: [mg53605] element selection
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 21 Jan 2005 06:35:36 -0500 (EST)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
n=100000; x=Sort[Table[Random[Integer,{0,10000}],{n}]]; y=Sort[Table[Random[Integer,{0,10000}],{n}]]; comp[x_?VectorQ,y_?VectorQ, maxDif_] := Select[Thread[{x,y}], Abs[#[[1]]-#[[2]]]<=maxDif&] /; Length[x]==Length[y]; Timing[Length[comp[x,y,2]]] {2.04 Second,16650} Bob Hanlon > > From: "Bruyndonckx P." <pbruynd at vub.ac.be> To: mathgroup at smc.vnet.net > Date: 2005/01/20 Thu AM 03:47:45 EST > To: mathgroup at smc.vnet.net > Subject: [mg53630] [mg53605] element selection > > I have two long sorted lists of Integers. If the difference between a number in list 1 and a > number in list 2 is less than a certain value, both are selected to create a couple. I am > looking for a fast way to go through both lists and extract these elements to create a new list > of couples. I tried a number of things, but all of them were rather slow so I need some expert > advice here. > > Thx, > > Peter > >