result = np.empty_like(x)
// Keep a copy of the rolling window in original order; initially fill with
// a mirrored copy of the first "wing" points
window = deque(np.concatenate((x[wing::-1], x[:wing])))
// Also keep a sorted copy of the rolling window values
sortwin = sorted(window)
// Pad the right edge of the original array with a mirror copy
signal = np.concatenate((x[wing:], x[:-wing-1:-1]))
// Calculate the rolling median at each subsequent point
for i, item in enumerate(signal):
After Change
// Pad the edges of the original array with mirror copies
signal = np.concatenate((x[wing-1::-1], x, x[:-wing-1:-1]))
rolled = pd.rolling_median(signal, 2 * wing + 1, center=True)
return rolled[wing:-wing]
def rolling_quantile(x, width, quantile):
Rolling quantile (0--1) with mirrored edges.