Re: Correlating two lists
- To: mathgroup at smc.vnet.net
- Subject: [mg100200] Re: Correlating two lists
- From: Ray Koopman <koopman at sfu.ca>
- Date: Thu, 28 May 2009 04:26:49 -0400 (EDT)
- References: <gv2jr1$9af$1@smc.vnet.net> <gvhm8r$82s$1@smc.vnet.net>
Function[xi,{xi,Sequence@@Select[y,R[xi,#]&,1]}] /@ x On May 26, 2:17 pm, anguz... at ing.uchile.cl wrote: > Hi all. > I have the following problem: > Two lists: "x" and "y"; and a boolean relation R[a,b] with a in x and > b in y, and for each "a" there is at most one "b" in "y" such that > R[xi,yj]is true. > R is also "expensive" to calculate. I would like to group each xi in > "x" with its partner in "y" (if there is one) and create a merged list: > {{x1,y1},{x2},{x3},{x4,y4},...} > such that R[xi,yi] is true > I'm looking for the adequate Mathematica function to do this as > efficiently as possible. by the way, I'm using now this > straightforward-naive approach: > > merged={}; > Do[Do[If[R[xi,yj],merged=Append[merged,{xi,yj}]],{yj,y}];If[MemberQ[merge[[All,1]],xi],merged=Append[merged,{xi}]],{xi,x}] > > but I'm sure there must be a better one > (without the Do's would be beautiful). > Any thoughts will be greatly appreciated. > Thanks in advance, and cheers for the 100.000 > > Atte. Andres Guzman > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program.