Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 ...
share|improve this question

marked as duplicate by Artes, rm -rf Oct 25 '12 at 22:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3  
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. :) –  Rahul Narain 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
add comment

3 Answers 3

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]
share|improve this answer
add comment

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} *)
share|improve this answer
    
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
add comment

This gives you the positions where both are True:

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

{{1}, {4}}

share|improve this answer
    
@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
add comment

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