[Date Index]
[Thread Index]
[Author Index]
Re: Mapping A Condition Across Two Different Lists
*To*: mathgroup at smc.vnet.net
*Subject*: [mg91760] Re: Mapping A Condition Across Two Different Lists
*From*: "David Park" <djmpark at comcast.net>
*Date*: Sun, 7 Sep 2008 05:37:38 -0400 (EDT)
*References*: <g9t6k5$j6g$1@smc.vnet.net>
Whenever you want to perform an operation involving two equal length lists
it is worthwhile looking into the Inner command.
listX = {4, 9, 2, 11, 4};
listY = {4, 0, 1, 8, 6};
targetX = 5;
targetY = 3;
Inner[targetX > #1 && targetY > #2 &, listX, listY, List]
{False, False, True, False, False}
Inner[targetX > #1 || targetY > #2 &, listX, listY, List]
{True, True, True, False, True}
Inner[#1 > #2 &, listX, listY, List]
{False, True, True, True, False}
Notice that we have to use List, rather than the default Plus, as the last
argument in the Inner statement.
Another common application of this technique is in combining equations.
eqn1 = x == a + b;
eqn2 = y == c + d;
Inner[Plus, eqn1, eqn2, Equal]
x + y == a + b + c + d
Inner[2 #1 + #2 &, eqn1, eqn2, Equal]
2 x + y == 2 (a + b) + c + d
--
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/
"Gregory Lypny" <gregory.lypny at videotron.ca> wrote in message
news:g9t6k5$j6g$1 at smc.vnet.net...
> 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
>
Prev by Date:
**Re: An Argument Problem**
Next by Date:
**Re: An Argument Problem**
Previous by thread:
**Re: Mapping A Condition Across Two Different Lists**
Next by thread:
**Re: Mapping A Condition Across Two Different Lists**
| |