How to sort a numpy array with key as isnan?

前端 未结 3 1702
遥遥无期
遥遥无期 2020-12-21 16:26

I have a numpy array like

np.array([[1.0, np.nan, 5.0, 1, True, True, np.nan, True],
       [np.nan, 4.0, 7.0, 2, True, np.nan, False, True],
       [2.0, 5         


        
3条回答
  •  醉话见心
    2020-12-21 17:03

    You can't do this with an object array and nan You would need to find a numeric type everything would fit into. When used as an object instead of as a float, nan returns false for <, >, and ==.

    Additionally, True and False are equivalent to 0 and 1, so I don't think there is any way to get your expected result.

    You would have to see if converting the dtype to float would give you proper results for your use case.

提交回复
热议问题