def groupby_app(A, WSZ):
    groups = itertools.groupby(A)
result = []
for group in groups:
    group_items = [item for item in group[1]]
group_length = len(group_items)
if group_length >= WSZ:
    result.extend([item for item in group_items])
else:
    result.extend([0] * group_length)
return result

def stride_tricks_app(arr, window):
    x = pd.rolling_min(arr, window)
x[:window - 1] = 0
y = np.lib.stride_tricks.as_strided(x, (len(x) - window + 1, window), (8, 8))
y[y[:, (-1)] == 1] = 1
return x.astype(int)
Filtering pandas or numpy arrays for continuous series with minimum window length