I am trying to figure out the fastest way to count how many time two values are located one after the other in a numpy list.
For example:
list = [1, 5, 4, 1, 2, 4, 6, 7, 2, 1, 3, 3, 1, 2]
and I want to count the number of times the value 1
follows the value 2
(but not vice versa)
In the example above, the answer should be 1
since 1
follows 2
only once.
I can obviously reach the answer with a simple for-loop that adds to a counter every time the item i
is equal 1
and item i-1
equals 2
, but I feel that there must be a faster way to do it,
Thanks