comparing numpy arrays containing NaN

后端 未结 7 1575
情话喂你
情话喂你 2020-11-28 09:27

For my unittest, I want to check if two arrays are identical. Reduced example:

a = np.array([1, 2, np.NaN])
b = np.array([1, 2, np.NaN])
if np.all(a==b):
          


        
7条回答
  •  日久生厌
    2020-11-28 10:14

    When I used the above answer:

     ((a == b) | (numpy.isnan(a) & numpy.isnan(b))).all()
    

    It gave me some erros when evaluate list of strings.

    This is more type generic:

    def EQUAL(a,b):
        return ((a == b) | ((a != a) & (b != b)))
    

提交回复
热议问题