This computes the "rolling max" of A
(similar to rolling average) over a sliding window of length K
:
import numpy as np
A = np.random.rand(100000)
K = 10
rollingmax = np.array([max(A[j:j+K]) for j in range(len(A)-K)])
but I think it is far from optimal in terms of performance.
I know that the pandas
library has rolling_max
, but in my project, I don't want to use this new dependance.
Question: is there a simple way to compute the rolling maximum with numpy only?