1

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 ...
Stephen Lien
  • 273
  • 2
  • 7
  • 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. :) –  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

3 Answers3

5

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]
kglr
  • 394,356
  • 18
  • 477
  • 896
4

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} *)
Verbeia
  • 34,233
  • 9
  • 109
  • 224
  • 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
2

This gives you the positions where both are True:

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

{{1}, {4}}

image_doctor
  • 10,234
  • 23
  • 40