Home > database >  Row index by change in column value?
Row index by change in column value?

Time:09-26

Having array like this :

[[0 1 0]
 [0 1 1]
 [0 1 1]
 [1 0 0]]

how do I pick the row indexes where a column for the first time becomes 1. Because there are 3 columns I have to get 3 row indexes.

In this case : 0,1,3

CodePudding user response:

You can use numpy.argmax with axis==0:

ind = arr.argmax(axis=0)
ind.sort() # sort if needed
ind

Output:

array([0, 1, 3])
  • Related