condition = [True, True, True, False, False, True, True, False, True]
[sum(1 for _ in group) for key, group in itertools.groupby(condition) if key]
Count consecutive occurences of values varying in length in a numpy array