title: Python NumPy - angled slice of 3D array
body: <p>Working in NumPy, I understand how to slice 2D arrays from a 3D array using <a href="http://www.pythoninformer.com/python-libraries/numpy/index-and-slice/" rel="nofollow noreferrer">this article</a>. </p>
  
  <p>Depending on the axis I'd want to slice in:</p>
  
  <pre><code>array = [[[0  1  2]
            [3  4  5]
            [6  7  8]]
  
           [[9  10 11]
            [12 13 14]
            [15 16 17]]
  
           [[18 19 20]
            [21 22 23]
            [24 25 26]]]
  </code></pre>
  
  <p>Slicing would give me:</p>
  
  <pre><code>i_slice = array[0]
  
      [[0  1  2]
       [3  4  5]
       [6  7  8]]
  
  j_slice = array[:, 0]
  
      [[0  1  2]
       [9  10 11]
       [18 19 20]]
  
  k_slice = array[:, :, 0]
  
      [[0  3  6]
       [9  12 15]
       [18 21 24]]
  </code></pre>
  
  <p><strong>But is it possible to slice at a 45 degree angle?</strong> such as:</p>
  
  <pre><code>j_slice_down = array[slice going down starting from index 0]
  
      [[0  1  2]
       [12 13 14]
       [24 25 26]]
  </code></pre>
  
  <p>I was able to achieve this in all 3 axis's going up or down, and even wrapping all the way around... in the dark list days with many for loops... but I'm sure there must be a better way in NumPy.</p>
  
  <h2>Update, chosen answer:</h2>
  
  <p>I chose hpaulj's answer creating two coordinate arrays with <code>np.arrange</code>. With a little work, I was able to make it fit my needs of returning a slice at any angle, on any axis, asymmetric dimension of 3D array, and at any position, including wrapping all the way around so that it is the same dimension as the axis. </p>
  
  <p><a href="https://i.stack.imgur.com/GZM8O.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GZM8O.gif" alt="My method using np.arrange"></a></p>
  
  <p>Two <code>np.arrange</code> arrays were made for an <code>x</code> and <code>y</code>. </p>
  
  <p>Different methods such as <code>np.roll</code>, incrementing, <code>np.hstack</code> and <code>np.concatenate</code> were done on the <code>np.arrange</code> array x axis array. <code>y = y[::-1]</code> for the alternate angle. </p>
  
  <pre><code>if axis is 'z': #i
      slice_notation = np.index_exp[x, y, :] 
  
  elif axis is 'y': #k
      slice_notation = np.index_exp[x, :, y]
  
  else: #j 
      slice_notation = np.index_exp[:, x, y]
  </code></pre>
  
  <p>Creates the slice expression, then I use the <code>slice_notation</code> to perform my needed operations in place. </p>
  
  <p>The other proposed methods: <code>np.diagonal</code> and <code>np.eye</code> may be more suitable for others though as they may have different requirements than me.</p>