3
[True,False,True,False] and [True,True,False,False]

it returns :

[True, True, False, False]

Why is the second element is True ?

DachuanZhao
  • 1,181
  • 3
  • 15
  • 34

1 Answers1

12

Because Python doesn't do element-wise vector operations like that. The way the normal and operator works is, if the first operand has a "true" value, then the result is the second value. Your first list is not empty, so it's true, so it returned the entire second list.

The numpy module does element-wise operations like that, but not straight Python.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30