// Gather windows & vectorize, so we can call math functions in one go
n_win = int(np.floor(len(sig) / win_len))
sig_rect = np.reshape(sig[:n_win * win_len], (n_win, win_len)).T
// get back the sig by taking the derivative of sig_walk
X = np.concatenate((sig[:1], np.diff(sig)))
X_rect = np.reshape(X[:n_win * win_len], (n_win, win_len)).T
// Calculate rescaled range as range divided by std, and take mean across windows
rs_win = np.ptp(sig_rect, axis=0) / np.std(X_rect, axis=0)
rs = np.mean(rs_win)
After Change
// Demean signal
sig = sig - np.mean(sig)
// Calculate cumulative sum of the signal & split the signal into segments
segments = split_signal(sp.cumsum(sig), win_len).T
// Calculate rescaled range as range divided by standard deviation (of non-cumulative signal)
rs_win = np.ptp(segments, axis=0) / np.std(split_signal(sig, win_len).T, axis=0)