如何获取numpy数组中所有NaN值的索引列表? [英] How to get the indices list of all NaN value in numpy array?
本文介绍了如何获取numpy数组中所有NaN值的索引列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在说我有一个numpy数组,定义为,
Say now I have a numpy array which is defined as,
[[1,2,3,4],
[2,3,NaN,5],
[NaN,5,2,3]]
现在,我要创建一个列表,其中包含缺失值的所有索引,在这种情况下为[(1,2),(2,0)]
.
Now I want to have a list that contains all the indices of the missing values, which is [(1,2),(2,0)]
at this case.
有什么办法可以做到吗?
Is there any way I can do that?
推荐答案
x = np.array([[1,2,3,4],
[2,3,np.nan,5],
[np.nan,5,2,3]])
np.argwhere(np.isnan(x))
输出:
array([[1, 2],
[2, 0]])
这篇关于如何获取numpy数组中所有NaN值的索引列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文