def sliding_window(sig, window=512, subsample=10, estimator=None):
    Ne, Ns = sig.shape
    # get the index before padding
    ix = range(0, Ns, subsample)

    # padd data
    padd = np.zeros((Ne, int(window) - 1))
    sig = np.concatenate((padd, sig), axis=1)
    Ne, Ns = sig.shape

    if estimator is None:
        estimator = np.array
    # call this to get the shape
    X = estimator(sig[:, 0:window])
    dims = list(X.shape)
    dims.insert(0, len(ix))
    dims = tuple(dims)

    # allocate array
    X = np.empty(dims, dtype=X.dtype)
    for i in range(len(ix)):
        X[i] = estimator(sig[:, ix[i]:(ix[i] + window)])

    return X
Extract a slinding window from signal.
dataset/ETHPy150Open alexandrebarachant/Grasp-and-lift-EEG-challenge/preprocessing/aux.py/sliding_window