def moving_rms(X, **kwargs):
    'Calculates moving rms of a signal with given window size. \n    Outputs np.array of *same* size as X. The rms of the \n    last few samples <= window_size away from the end are assigned\n    to last full-window rms calculated\n    Parameters\n    ----------\n    X :  np.array\n        Signal of interest. \n    window_size : int, optional\n                 Defaults to 125 samples. \n    Returns\n    -------\n    all_rms : np.array\n        Moving rms of the signal. \n    '
    window_size = kwargs.get('window_size', 125)
    starts = np.arange(0, X.size)
    stops = (starts + window_size)
    valid = (stops < X.size)
    valid_starts = np.int32(starts[valid])
    valid_stops = np.int32(stops[valid])
    all_rms = (np.ones(X.size).reshape((- 1), 1) * 999)
    for (i, (start, stop)) in enumerate(zip(valid_starts, valid_stops)):
        rms_value = rms(X[start:stop])
        all_rms[i] = rms_value
    all_rms[(all_rms == 999)] = np.nan
    return all_rms
Calculates moving rms of a signal with given window size. 
Outputs np.array of *same* size as X. The rms of the 
last few samples <= window_size away from the end are assigned
to last full-window rms calculated
Parameters
----------
X :  np.array
    Signal of interest. 
window_size : int, optional
             Defaults to 125 samples. 
Returns
-------
all_rms : np.array
    Moving rms of the signal.
def moving_rms(X, **kwargs):
    'Calculates moving rms of a signal with given window size. \n    Outputs np.array of *same* size as X. The rms of the \n    last few samples <= window_size away from the end are assigned\n    to last full-window rms calculated\n    Parameters\n    ----------\n    X :  np.array\n        Signal of interest. \n    window_size : int, optional\n                 Defaults to 125 samples. \n    Returns\n    -------\n    all_rms : np.array\n        Moving rms of the signal. \n    '
    window_size = kwargs.get('window_size', 125)
    starts = np.arange(0, X.size)
    stops = (starts + window_size)
    valid = (stops < X.size)
    valid_starts = np.int32(starts[valid])
    valid_stops = np.int32(stops[valid])
    all_rms = (np.ones(X.size).reshape((- 1), 1) * 999)
    for (i, (start, stop)) in enumerate(zip(valid_starts, valid_stops)):
        rms_value = rms(X[start:stop])
        all_rms[i] = rms_value
    all_rms[(all_rms == 999)] = np.nan
    return all_rms