Suppose I have a numpy array, for example:
a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [3, 2, 1]])
I want to check if there is a second element == 2.
I know I can do this:
>>> a[:,1]==2 array([ True, False, False, True], dtype=bool)
returns boolean values. My question is: how do I get line numbers in lines where the condition is true? In this example, I would like to return array([0, 3]) , because the 0th and 3rd rows correspond to the condition of the second element == 2.
python arrays numpy
Ben S.
source share