0

I want to select the max/min value after a certain time interval. Something similar to sliding or rolling window but calculating the max/min values in section. Here an example [6 3 7 4 6 9 2 6 7 4 3 7 8 2 5 4 1 7 5 1]. In this instance I want the window to calculate the max of the first 5 values and then the max value from the next section (index 6 to 10) and so on.

select a max value 7 from this portion [6 3 7 4 6]
select a max value 9 from this portion [9 2 6 7 4] 
select a max value 8 from this portion [3 7 8 2 5] 
select a max value 7 from this portion [4 1 7 5 1] 

Any ideas on how to do it. Some sort of function that allows me to adjust the window length as well, i.e for 5 to 3. Thanks in advance

imantha
  • 2,676
  • 4
  • 23
  • 46
  • @ sshashank124 as I understand it they are asking over a rolling window, and it just so happens they have no overlap in their example. – Daniel F Jan 13 '20 at 07:15

1 Answers1

1

You can reshape the numpy array and then get the max

>>> arr = np.array([6, 3, 7, 4, 6, 9, 2, 6, 7, 4, 3, 7, 8, 2, 5, 4, 1, 7, 5, 1])
>>> arr = arr.reshape(-1,5)
>>> arr.max(axis=1)
array([7, 9, 8, 7])
abc
  • 11,579
  • 2
  • 26
  • 51