code: def cumargmax(a):
      
  
      # Thank you @Alex Riley
      # https://stackoverflow.com/a/40675969/7954504
  
      m = np.asarray(np.maximum.accumulate(a))
      if a.ndim == 1:
          x = np.arange(a.shape[0])
      else:
          x = np.repeat(np.arange(a.shape[0])[:, None], a.shape[1], axis=1)
  
      x[1:] *= m[:-1] < m[1:]
      np.maximum.accumulate(x, axis=0, out=x)
      return x
docs: Cumulative argmax.
  
      Parameters
      ----------
      a : np.ndarray
  
      Returns
      -------
      np.ndarray