MathGroup Archive 2006

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

Search the Archive

Re: MapThread and If

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68049] Re: MapThread and If
  • From: bbhole at gmail.com
  • Date: Fri, 21 Jul 2006 05:37:42 -0400 (EDT)
  • References: <e9nkro$9u3$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Arek,

The following works but may not be the best way to do it.

In[1]: MapThread[If[(MemberQ[#2, #1] || #1 == #2), 0, tr] &, {{1, 2,
3}, {{1,2},2,2}}]

Out[1]: {0,0,tr}

This assumes that the second list is atmost 1 level deep. If it is
deeper, i.e., instead of say {1,2} in the second list you have {{1},2}
and you still want zero then you can modify

MemberQ[#2, #1] TO MemberQ[#2, #1,2].


Arkadiusz Majka wrote:
> Hi,
>
> 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}.
> 
> Thx,
> 
> Arek


  • Prev by Date: Re: MapThread and If
  • Next by Date: Re: InputForm changes the order of output?
  • Previous by thread: Re: MapThread and If
  • Next by thread: Re: MapThread and If