# List-threading operations with logicals

Posted 9 years ago
2800 Views
|
6 Replies
|
7 Total Likes
|
 {2,3,4}+3 delivers {5,6,7}I'd like {2,3,4}==3 to deliver {False, True, False}, but it doesn't. Can I make it do that?Jim Simons
6 Replies
Sort By:
Posted 9 years ago
 It probably depends on what one is looking for. Nasser's suggestion seems to be the fastest one:  (Outer[Equal, {3}, RandomInteger[3, 10^6]] //Flatten); // AbsoluteTiming (*{0.167448, Null}*) It only takes a third of the time that mine takes. This is the shortest one in terms of symbols used:  (# == 3) & /@ RandomInteger[3, 10^6]; // AbsoluteTiming (*{0.467847, Null}*) This one's quite clear to read... Thread[RandomInteger[3, 10^6] == 3]; // AbsoluteTiming (*{0.247238, Null}*) M.
Posted 9 years ago
 Ah, I see Frank got there 5 seconds before me!!
Posted 9 years ago
 Thanks guys, but I've discovered a different, and IMHO better, answer:Thread[{2,3,4}==3]Jim
Posted 9 years ago
 In[2]:= Thread[{2, 3, 4} == 3]Out[2]= {False, True, False}
Posted 9 years ago
 Another possible way lis = {2, 3, 4}; Outer[Equal, {3},lis] // Flatten (* {False, True, False} *) 
Posted 9 years ago
 I think that this might work: (# == 3) & /@ {2, 3, 4} It does appear to give the result you want.M.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.