MathGroup Archive 2008

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

Search the Archive

Re: Mapping A Condition Across Two Different Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91738] Re: [mg91705] Mapping A Condition Across Two Different Lists
  • From: Gregory Lypny <gregory.lypny at videotron.ca>
  • Date: Sun, 7 Sep 2008 05:33:26 -0400 (EDT)
  • References: <20080906091553.7CU18.147801.imail@eastrmwml41>

Thank you, Jean-Marc and Bob,

Elegant solutions.  I find the one with Transpose to be more intuitive  
because it's not obvious that Thread is threading the joint  
comparison, which it is, and which I guess is another example of  
Mathematica's scope.

Regards and thanks again,

	Gregory


On Sat, Sep 6, 2008, at 11:56 AM, Jean-Marc Gulliet wrote:
>
> Among other ways, you could map over the transpose of list of the  
> two lists, e.g.
>
>  In[1]:= targetX = 5; listX = {4, 9, 2, 11, 4};
>    targetY = 3; listY = {4, 0, 1, 8, 6};
>
>    targetX > #[[1]] && targetY > #[[2]] & /@ Transpose[{listX, listY}]
>
>    targetX > #[[1]] || targetY > #[[2]] & /@ Transpose[{listX, listY}]
>
>  Out[3]= {False, False, True, False, False}
>
>  Out[4]= {True, True, True, False, True}
>
> Best regards,
> -- Jean-Marc
>




On Sat, Sep 6, 2008, at 9:15 AM, Bob Hanlon wrote:

> targetX = 5; listX = {4, 9, 2, 11, 4};
>
> targetY = 3; listY = {4, 0, 1, 8, 6};
>
> Thread[(targetX > # & /@ listX) &&
>  (targetY > # & /@ listY)]
>
> {False,False,True,False,False}
>
> targetX > #[[1]] && targetY > #[[2]] & /@
> Transpose[{listX, listY}]
>
> {False,False,True,False,False}
>
> % == %%
>
> True
>
> Thread[(targetX > # & /@ listX) ||
>  (targetY > # & /@ listY)]
>
> {True,True,True,False,True}
>
> targetX > #[[1]] || targetY > #[[2]] & /@
> Transpose[{listX, listY}]
>
> {True,True,True,False,True}
>
> % == %%
>
> True
>
>
> Bob Hanlon
>
> ---- Gregory Lypny <gregory.lypny at videotron.ca> wrote:
>
> =============
> Hello everyone,
>
> Not sure how to do this using Map, or even if it's possible.
>
> I can compare a target value to each value in a list like this.
>
> targetX = 5; listX = {4, 9, 2, 11, 4};
> targetX > # & /@ listX
>
> {True, False, True, False, True}
>
> I can do the same for another target and another list.
>
> targetY = 3; listY = {4, 0, 1, 8, 6};
> targetY > # & /@ listY
>
> {False, True, True, False, False}
>
> But can I do it in a similar way for the AND or OR condition without
> having to resort to the Table command?
>
> Table[targetX > listX[[i]] && targetY > listY[[i]], {i, Length@listX}]
>
> {False, False, True, False, False}
>
> Table[targetX > listX[[i]] || targetY > listY[[i]], {i, Length@listX}]
>
> {True, True, True, False, True}
>
> Much obliged,
>
> 	Gregory
>
>
> --
>
> Bob Hanlon
>


  • Prev by Date: Re: Mapping A Condition Across Two Different Lists
  • Next by Date: Re: LU Decomposition w/o Pivoting
  • Previous by thread: Re: Mapping A Condition Across Two Different Lists
  • Next by thread: phase-space versus controlling parameter surface