我有以下数组:

a = np.array([1,2,9], [5,2,4], [1,2,3])

任务是查找行和大于10的所有行的索引,在我的示例中,结果应该类似于[0,1]
我需要一个类似于本文推荐的过滤器:
Filter rows of a numpy array?
但是,我只需要索引,而不需要实际值或它们自己的数组。
我当前的代码如下:
temp = a[np.sum(a, axis=1) > 5]

如何获取筛选行的初始索引?

最佳答案

您可以像这样使用np.argwhere()

>>> import numpy as np

>>> a = np.array([[1,2,9], [5,2,4], [1,2,3]])
>>> np.argwhere(np.sum(a, axis=1) > 10)
[[0]
 [1]]

07-24 09:52
查看更多