{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
{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
I think that this might work:
(# == 3) & /@ {2, 3, 4}
It does appear to give the result you want.
M.
Another possible way
lis = {2, 3, 4};
Outer[Equal, {3},lis] // Flatten
(* {False, True, False} *)
In[2]:= Thread[{2, 3, 4} == 3]
Out[2]= {False, True, False}
Thanks guys, but I’ve discovered a different, and IMHO better, answer:
Thread[{2,3,4}==3]
Jim
Ah, I see Frank got there 5 seconds before me!!
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.