# Message Boards

0
|
3318 Views
|
6 Replies
|
7 Total Likes
View groups...
Share
GROUPS:

Posted 11 years ago
 {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 11 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 11 years ago
 Ah, I see Frank got there 5 seconds before me!!
Posted 11 years ago
 Another possible way lis = {2, 3, 4}; Outer[Equal, {3},lis] // Flatten (* {False, True, False} *) 
 I think that this might work: (# == 3) & /@ {2, 3, 4} It does appear to give the result you want.M.