I want to create an array which holds all the max()es of a window moving through a given numpy array. I\'m sorry if this sounds confusing. I\'ll give an examp
If you have two dimension data, for example stock price and want to get rolling max or whatever, this will works. Caculating without using iteration.
n = 5 # size of rolling window
data_expanded = np.expand_dims(data, 1)
data_shift = [np.roll(data_expanded, shift=-i, axis=2) for i in range(n)]
data_shift = np.concatenate(data_shift, axis=1)
data_max = np.max(data_shift, axis=1) # max, mean, std...