title: Numpy: argmax over multiple axes without loop
body: <p>I have a N-dimensional array (Named A). For each row of the first axis of A, I want to obtain the coordinates of the maximum value along the other axes of A. Then I would return a 2-dimensional array with the coordinates of the maximum value for each row of the first axis of A.</p>
  
  <p>I already solved my problem using a loop, but I was wondering whether there is a more efficient way of doing this. My current solution (for an example array A) is as follows:</p>
  
  <pre><code>import numpy as np
  
  A=np.reshape(np.concatenate((np.arange(0,12),np.arange(0,-4,-1))),(4,2,2))
  maxpos=np.empty(shape=(4,2))
  for n in range(0, 4):
      maxpos[n,:]=np.unravel_index(np.argmax(A[n,:,:]), A[n,:,:].shape)
  </code></pre>
  
  <p>Here, we would have:</p>
  
  <pre><code>A: 
  [[[ 0  1]
    [ 2  3]]
  
   [[ 4  5]
    [ 6  7]]
  
   [[ 8  9]
    [10 11]]
  
   [[ 0 -1]
    [-2 -3]]]
  
  maxpos:
  [[ 1.  1.]
   [ 1.  1.]
   [ 1.  1.]
   [ 0.  0.]]
  </code></pre>
  
  <p>If there are multiple maximizers, I don't mind which is chosen. </p>
  
  <p>I have tried to use <code>np.apply_over_axes</code>, but I haven't managed to make it return the outcome I want.</p>