title: how to get the diagonal components of numpy 3-D array?
body: <p>I have an 3-D array like</p>
  
  <pre><code>a = np.array(
      [[[1, 2],
        [3, 4]],
  
       [[5, 6],
        [7, 8]]]
  )
  </code></pre>
  
  <p>and I want to get the diagonal component from this array, I mean,</p>
  
  <pre><code>&gt;&gt; np.array([a[i,i,:] for i in range(min(a.shape[0], a.shape[1]))])
  array([[1, 2],
         [7, 8]])
  </code></pre>
  
  <p>Is there any faster way to do the same as above?</p>