How to get the indices list of all NaN value in numpy array?

后端 未结 3 662
一个人的身影
一个人的身影 2020-12-02 10:56

Say now I have a numpy array which is defined as,

[[1,2,3,4],
[2,3,NaN,5],
[NaN,5,2,3]]

Now I want to have a list that contains all the ind

3条回答
  •  青春惊慌失措
    2020-12-02 11:50

    Since x!=x returns the same boolean array with np.isnan(x) (because np.nan!=np.nan would return True), you could also write:

    np.argwhere(x!=x)
    

    However, I still recommend writing np.argwhere(np.isnan(x)) since it is more readable. I just try to provide another way to write the code in this answer.

提交回复
热议问题