numpy获取索引,其中值是true [英] numpy get index where value is true
本文介绍了numpy获取索引,其中值是true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
>>> ex=np.arange(30)
>>> e=np.reshape(ex,[3,10])
>>> e
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29]])
>>> e>15
array([[False, False, False, False, False, False, False, False, False,
False],
[False, False, False, False, False, False, True, True, True,
True],
[ True, True, True, True, True, True, True, True, True,
True]], dtype=bool)
我需要找到具有true的行或e
中值大于15的行.我可以使用for循环进行迭代,但是,我想知道是否有numpy可以执行更多操作有效吗?
I need to find the rows that have true or rows in e
whose value are more than 15. I could iterate using a for loop, however, I would like to know if there is a way numpy could do this more efficiently?
推荐答案
要获取至少一项大于15的行号:
To get the row numbers where at least one item is larger than 15:
>>> np.where(np.any(e>15, axis=1))
(array([1, 2], dtype=int64),)
这篇关于numpy获取索引,其中值是true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文