import numpy as np
I have two arrays:
a = np.array([1,2,3,np.nan,5])
b = np.array([3,2,np.nan,5,4])
I would like to compare the elements in these two arrays & get a list of booleans as result. When there is nan involved in the comparison, I'd like to get nan. Expected result:
[False, False, nan, nan, True]
I have achieved the desired output using an if-else involving list comprehension:
[eacha>eachb
 if ~np.isnan(eacha) and ~np.isnan(eachb)
 else np.nan
 for eacha, eachb in zip(a,b)]
Is there a better (ie not involving for loop, if-else statements) way of doing this?
 
    