Python 如何从numpy 2d数组中找到大于特殊数的元素索引?

Python 如何从numpy 2d数组中找到大于特殊数的元素索引?,python,arrays,numpy,indexing,find,Python,Arrays,Numpy,Indexing,Find,我想从numpy 2d数组中找到大于2的元素索引 像这样 import numpy as np a = np.array([[1,2,3],[4,5,6]]) # find indices of element that bigger than 2 # result = [[0,2],[[1,0],[1,1],[1,2]] 您可以使用np.where(),它将在元组模式下为您提供预期的索引(单独的轴): 或者直接使用np.argwhere(): 我希望解决方案不使用双for循环zip(*

我想从numpy 2d数组中找到大于2的元素索引

像这样

import numpy as np
a = np.array([[1,2,3],[4,5,6]])

#  find indices of element that bigger than 2
# result  = [[0,2],[[1,0],[1,1],[1,2]]
您可以使用
np.where()
,它将在元组模式下为您提供预期的索引(单独的轴):

或者直接使用
np.argwhere()


我希望解决方案不使用双for循环
zip(*np.where(a>2))
-`<代码>np.argwhere(a>2)-谢谢!我得试试这个。谢谢你的回答!
In [6]: np.where(a>2)
Out[6]: (array([0, 1, 1, 1]), array([2, 0, 1, 2]))
In [5]: np.argwhere(a>2)
Out[5]: 
array([[0, 2],
       [1, 0],
       [1, 1],
       [1, 2]])