cumulative argmax of a numpy array
<p>Consider the array <code>a</code></p>

<pre><code>np.random.seed([3,1415])
a = np.random.randint(0, 10, (10, 2))
a

array([[0, 2],
       [7, 3],
       [8, 7],
       [0, 6],
       [8, 6],
       [0, 2],
       [0, 4],
       [9, 7],
       [3, 2],
       [4, 3]])
</code></pre>

<p>What is a vectorized way to get the cumulative argmax?</p>

<pre><code>array([[0, 0],  &lt;-- both start off as max position
       [1, 1],  &lt;-- 7 &gt; 0 so 1st col = 1, 3 &gt; 2 2nd col = 1
       [2, 2],  &lt;-- 8 &gt; 7 1st col = 2, 7 &gt; 3 2nd col = 2
       [2, 2],  &lt;-- 0 &lt; 8 1st col stays the same, 6 &lt; 7 2nd col stays the same
       [2, 2],  
       [2, 2],
       [2, 2],
       [7, 2],  &lt;-- 9 is new max of 2nd col, argmax is now 7
       [7, 2],
       [7, 2]])
</code></pre>

<hr>

<p>Here is a non-vectorized way to do it. </p>

<p>Notice that as the window expands, argmax applies to the growing window.</p>

<pre><code>pd.DataFrame(a).expanding().apply(np.argmax).astype(int).values

array([[0, 0],
       [1, 1],
       [2, 2],
       [2, 2],
       [2, 2],
       [2, 2],
       [2, 2],
       [7, 2],
       [7, 2],
       [7, 2]])
</code></pre>