avg_val = np.tile(val[:, (None)] / (2 * win + 1), (1, 2 * win + 1))
unique_idx, _ = np.unique(avg_idx, return_inverse=True)
Efficiently take moving average of sparse data and filter above threshold in python