This is the same reason why:
>>> (1,2) and (3,4)
(3, 4)
You need to understand that this is not doing element-wise comparison as opposed to np.logical_and
.
The way and
works is, if you have a and b
, it checks whether a
is False
, if yes, return a
else return b
, does not matter what the value of b
is.
In your case [False, True]
is not False
:
>>> bool([False, True])
True
Because it is a non-empty list, even [False, False]
is True
.
So in the case of [False, True] and [True, False]
, it checks to see whether [False, True]
is False
, which it is not, so it returns the second value. Same for the other case.
A python implementation of the and
or
logic would be:
def AND(first, second):
if bool(first) == True:
return second
else:
return first
def OR(first, second):
if bool(first) == True:
return first
else:
return second