0

I have a list L. It has random numbers.

I want to get the index of maximum number among each 4 numbers of L.

What is the way to do it ?

I can get the max value from below (i guess ) but not sure how to get index value ? Also is there a way to do same in nd array ???

import pandas as pd
a=np.random.rand(100)
L=list(a)
pd.rolling_max(L, 4)

1 Answers1

0

There is no quicker way than to run through the list looking at the 4 size subsets. For each subset, you can have a variable that stores the index of the maximum number seen so far (among the 4). This is O(n) which is the quickest you can do it because you will have to look at each number in the list at least once.

Riwaz Poudyal
  • 855
  • 1
  • 8
  • 15