Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中获取数组中所有NaN元素的索引?_Python_Arrays_Python 3.x_Indexing - Fatal编程技术网

如何在python中获取数组中所有NaN元素的索引?

如何在python中获取数组中所有NaN元素的索引?,python,arrays,python-3.x,indexing,Python,Arrays,Python 3.x,Indexing,我有一个数组 [ nan, nan, nan, 1633.32, 1661.24, 0. ], [ nan, nan, nan, 2885.94, 3264.09, 0. ], [ 605.48, nan, 599.27, 664.47, 670.68, 0. ], [ nan, nan, nan, 874.59, 78

我有一个数组

   [     nan,      nan,      nan,  1633.32,  1661.24,     0.  ],
   [     nan,      nan,      nan,  2885.94,  3264.09,     0.  ],
   [  605.48,      nan,   599.27,   664.47,   670.68,     0.  ],
   [     nan,      nan,      nan,   874.59,   783.86,     0.  ],
   [ 1596.01,      nan,  1469.77,  1731.26,  1514.86,     0.  ]]

使用
np.isnan
np.argwhere
函数组合从
numpy
模块了解元素“nan”的索引(行、列)有何方法

import numpy as np

arr = np.array([[     np.NaN,      np.NaN,      np.NaN,  1633.32,  1661.24,     0.  ],
   [     np.NaN,      np.NaN,      np.NaN,  2885.94,  3264.09,     0.  ],
   [  605.48,      np.NaN,   599.27,   664.47,   670.68,     0.  ],
   [     np.NaN,      np.NaN,      np.NaN,   874.59,   783.86,     0.  ],
   [ 1596.01,      np.NaN,  1469.77,  1731.26,  1514.86,     0.  ]])

print(np.argwhere(np.isnan(arr)))
输出:

[[0 0]
 [0 1]
 [0 2]
 [1 0]
 [1 1]
 [1 2]
 [2 1]
 [3 0]
 [3 1]
 [3 2]
 [4 1]]

嗨,朱,你试了什么?你的问题是什么?@MarcusMüller我的问题是从数组中获取行、列索引,无论它的值是“nan”/null,我一直在关注其他人的做法。我跨越了列表理解:索引=[I for I,x in enumerate(my_list)if x==“nan”]但是因为它对于列表只给出了列索引,所以我想在数组上执行它,所以我需要行和列索引号。
来自math import isnan;[(r,c)表示r,枚举(数据)中的行表示c,枚举(行)中的项表示isnan(项)]