Skip to main content
Became Hot Network Question
Tweeted twitter.com/StackMma/status/1575998974556766211
edited tags
Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Source Link

How to Thread lists elementwise with the If function?

Consider the lists:

list1={a,b,c};
list2={x,y,z};

I want to Thread If elementwise across the lists. I can achieve this with MapThread but cannot with Thread

In[1]:= MapThread[If[#1>#2,1,0]&,{list1,list2}]
Out[1]= {If[a>x,1,0],If[b>y,1,0],If[c>z,1,0]}

It fails when I try to do it with Thread

In[2]:= Thread[If[#1>#2,1,0]&[list1,list2]]
Out[2]= If[{a,b,c}>{x,y,z},1,0]

Academic Question

How can I perform the functionality with Thread instead of MapThread ?