Logical operators doubt

Course Name: Python for Trading: Basic, Section No: 7, Unit No: 15, Unit type: Notebook



Logical operators

In [23]:

 
# This should be self explanatory by now
a = np.array([[True, True], [False, False]])
b = np.array([[True, False], [True, False]])
print(np.logical_or(a, b))
[[ True  True]
 [ True False]]

In [24]:

 

print(np.logical_and(a, b))
[[ True False]
 [False False]]


I don't understand these last Logical operators section. I've tried reading back what was explained in Other operators, that I totally understood but I don't get the Logical operators one. Can someone please explain?

Hi Alvaro



I have tried to break it down for you in the image below:







From the two arrays A and B, the values go to Logical OR and Logical AND. Purple values correspond to Array A and Pink values correspond to Array B. These are then evaluated as per the OR and AND conditions you have learnt previously. The final evaluation is shown in the last part in orange, which matches the output from numpy methods.



Hope this helps.