Re: Mapping A Condition Across Two Different Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg91766] Re: Mapping A Condition Across Two Different Lists
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sun, 7 Sep 2008 05:38:47 -0400 (EDT)
On 9/6/08 at 2:06 AM, gregory.lypny at videotron.ca (Gregory Lypny) wrote: >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? You could do it with Map as follows: In[4]:= (targetY > First@# && targetX > Last@#) & /@ Transpose@{listY, listX} Out[4]= {False,False,True,False,False} but MapThread is specifically designed for this task. For example, In[5]:= MapThread[targetY > #1 && targetX > #2 &, {listY, listX}] Out[5]= {False,False,True,False,False}