# Logical operations on a list [duplicate]

Possible Duplicate:
Applying And to lists of Booleans

I have two lists filled with logicals:

demondata = {True, True, False, True}
numerdata = {True, False, True, True}


I would like to find which corresponding cells positions are both True. The only code I could come up with is:

toInclude = MapThread[And, {demondata, numerdata}];


Is there a way to do something like:

demondata && numerdata


Not that there is something wrong with MapThread, it just seems more complicated than I thought it would be. In MATLAB, I can do:

list1 & list2  _or_  list1 > 10   etc ...

• By the way... The word that goes with numerator is denominator. On the other hand, Demonimator sounds like an excellently cheesy sci-fi horror flick. :) – user484 Oct 25 '12 at 22:39
• @artes I've a feeling that my answer may address this question , but is not a valid answer to the proposed duplicate ? – image_doctor Oct 25 '12 at 23:55

You need use MapThread as

MapThread[And,{demondata,numerdata}]
(* {True, False, False, True} *)


Perhaps

 demondata && numerdata // Thread


is close enough?

And ... there is also:

Inner[And, demondata, numerdata, List]


MapThread isn't that complicated but if you are looking for alternatives, two options spring to mind:

And @@@ Transpose[{demondata, numerdata}]
(* {True, False, False, True} *)


Or if you don't mind switching to 0s and 1s instead of logical values:

Boole[demondata]*Boole[numerdata]
(* {1, 0, 0, 1} *)

• I just wanted to make sure I wasn't missing something more fundamental. I thought the same way you can add lists without map, you may be able to do logical operations on lists. – Stephen Lien Oct 25 '12 at 22:53

This gives you the positions where both are True:

{demondata, numerdata}\[Transpose]~Position~{True, True}


{{1}, {4}}

• @rojo oops, yes you are right :) Fixed now, thank you. – image_doctor Oct 25 '12 at 23:27
• Deleting the comment because you fixed it, +1 – Rojo Oct 25 '12 at 23:46