Find all n-dimensional lines and diagonals with NumPy : <p>Using NumPy, I would like to produce a list of all lines and diagonals of an n-dimensional array with lengths of k.</p>

<hr>

<p>Take the case of the following three-dimensional array with lengths of three.</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>For this case, I would like to obtain all of the following types of sequences. For any given case, I would like to obtain all of the possible sequences of each type. Examples of desired sequences are given in parentheses below, for each case.</p>

<ul>
<li>1D lines

<ul>
<li>x axis (<code>0, 1, 2</code>)</li>
<li>y axis (<code>0, 3, 6</code>)</li>
<li>z axis (<code>0, 9, 18</code>)</li>
</ul></li>
<li>2D diagonals

<ul>
<li>x/y axes (<code>0, 4, 8</code>, <code>2, 4, 6</code>)</li>
<li>x/z axes (<code>0, 10, 20</code>, <code>2, 10, 18</code>)</li>
<li>y/z axes (<code>0, 12, 24</code>, <code>6, 12, 18</code>)</li>
</ul></li>
<li>3D diagonals

<ul>
<li>x/y/z axes (<code>0, 13, 26</code>, <code>2, 13, 24</code>)</li>
</ul></li>
</ul>

<hr>

<p>The solution should be generalized, so that it will generate all lines and diagonals for an array, regardless of the array's number of dimensions or length (which is constant across all dimensions).</p>
