Re: MapThread and If
- To: mathgroup at smc.vnet.net
- Subject: [mg68045] Re: MapThread and If
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Fri, 21 Jul 2006 05:37:38 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 7/20/06 at 6:04 AM, Arkadiusz.Majka at telekomunikacja.pl (Arkadiusz
Majka) wrote:
>Of course
>MapThread[If[#1 == #2, 0, tr] &, {{1, 2, 3}, {2, 2, 4}}]
>I get
>{tr, 0, tr}
>and for
>MapThread[If[#1 == #2, 0, tr] &, {{1, 2, 3}, {2, 2, {3, 4}}}]
>I get
>{tr, 0, If[3 == {3, 4}, 0, tr]}
>How I can build in above MapThread expression information that if
>'a' is equal to any element from the list {a,b,c,d} the result is 0.
>In above example we have If[3=={3,4},0,tr] what I want to be 0,
>because 3 is equal to an element belonging to {3,4}.
Use MemberQ i.e.,
In[26]:=
MapThread[If[#1==#2 || MemberQ[#2,#1],0,tr]&,{{1,2,3},{2,2,{3,4}}}]
Out[26]=
{tr,0,0}
or equivalently
In[29]:=
MapThread[If[MemberQ[Flatten@{#2},#1],0,tr]&,{{1,2,3},{2,2,{3,4}}}]
Out[29]=
{tr,0,0}
--
To reply via email subtract one hundred and four