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 ...
  • 3
    $\begingroup$ 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. :) $\endgroup$
    – user484
    Oct 25 '12 at 22:39
  • $\begingroup$ @artes I've a feeling that my answer may address this question , but is not a valid answer to the proposed duplicate ? $\endgroup$ Oct 25 '12 at 23:55

You need use MapThread as

(* {True, False, False, True} *)


 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:

(* {1, 0, 0, 1} *)
  • $\begingroup$ 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. $\endgroup$ Oct 25 '12 at 22:53

This gives you the positions where both are True:

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

{{1}, {4}}

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.