x = [1,1,1,1]
y = [1,1,1,1]
np.logical_and(x == 1, y == 1)
Output: False
I am expecting an output of [True, True, True, True]. How to achieve this?
In your example x and y are lists not arrays. When you compare a list with an integer using == you'll always get False:
>>> [1,1,1,1] == 1
False
>>> [1,1,1,1] == 1
False
>>> np.logical_and(False, False)
False
You have to convert them to arrays, because arrays implement == to work element-wise:
>>> x = np.array([1, 1, 1, 1])
>>> x == 1
array([ True, True, True, True])
>>> x = np.array([1, 1, 1, 1])
>>> y = np.array([1, 1, 1, 1])
>>> np.logical_and(x == 1, y == 1)
array([ True, True, True, True])