Given a numpy array:
x = np.array([False, True, True, False, False, False, False, False, True, False])
How to find the number of transitions between False and True? In the above example, the answer will be 2. I do not want to include the transitions from True to False in the score.
From the answers to How to determine the sequence of values ββin a Boolean array? , below are the indexes whose values ββwill be changed, which is not what I want, as this includes True-False transitions.
np.argwhere(np.diff(x)).squeeze() # [0 2 7 8]
I know this can be done by going through an array, however I was wondering if there is a faster way to do this?
source share