You can use numpy masking and itertools.groupby.
from itertools import groupby
b = 6
sum(len(list(g))>=2 for i, g in groupby(a < b) if i)
#3
solved Count the number of times elements in a numpy array consecutively satisfy a condition
You can use numpy masking and itertools.groupby.
from itertools import groupby
b = 6
sum(len(list(g))>=2 for i, g in groupby(a < b) if i)
#3
solved Count the number of times elements in a numpy array consecutively satisfy a condition