Issue
>>> 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)
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?
Solution
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),)
Answered By - Jaime
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.