I'd like to take {True,True,False}
and {True,False,False}
and apply And
to get {True,False,False}
. Right now I'm using
And @@ # & /@ Transpose[{{True, True, False}, {True, False, False}}]
Is that really the best way? I would like And[{True, True, False}, {True, False, False}]
to work but it does not.
Answer
I like more :
MapThread[ And, {{True, True, False}, {True, False, False}}]
{True, False, False}
Edit
We should test efficiency of various methods for a few different lists.
Definitions
Argento[l_] := (And @@ # & /@ Transpose[l]; // AbsoluteTiming // First)
Brett[l_] := (And @@@ Transpose[l]; // AbsoluteTiming // First)
Artes[l_] := (MapThread[And, l]; // AbsoluteTiming // First)
kguler[l_] := (And[l[[1]], l[[2]]] // Thread; // AbsoluteTiming // First)
RM[l_] := (Inner[And, l[[1]], l[[2]], List]; // AbsoluteTiming // First)
Test I
l1 = RandomChoice[{True, False}, {2, 10^5}];
Argento[l1]
Brett[l1]
Artes[l1]
kguler[l1]
RM[l1]
0.2710000
0.0820000
0.0530000
0.0520000
0.0390000
Test II
l2 = RandomChoice[{True, False}, {2, 7 10^5}];
Argento[l2]
Brett[l2]
Artes[l2]
kguler[l2]
RM[l2]
1.4690000
0.5820000
0.3840000
0.3700000
0.2890000
Test III
l3 = RandomChoice[{True, False}, {2, 3 10^6}];
Argento[l3]
Brett[l3]
Artes[l3]
kguler[l3]
RM[l3]
6.2320000
2.4750000
1.6530000
1.4150000
1.2150000
Comments
Post a Comment