comparing numpy arrays containing NaN

后端 未结 7 1526
情话喂你
情话喂你 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:27

    I'm not certain this is the best way to proceed, but it is a way:

    >>> ((a == b) | (numpy.isnan(a) & numpy.isnan(b))).all()
    True
    
    0 讨论(0)
提交回复
热议问题