What is the fastest way to put the first axis behind the last one? [numpy]
<p>Let us look at this stupid example with a N0 x N1 x ... x Nm dimensional array, such as </p>

<pre><code>import numpy as np
x = np.random.random([N0,N1,...,Nm]) 
</code></pre>

<p>Now I want the N0 dimension to be behind the last one, i.e.</p>

<pre><code>np.swapaxis np.swapaxis(np.swapaxis(x, 0,1),1,2) ... # swapping m times
</code></pre>

<p>I tried with np.rollaxis, but this seems to be the wrong function. In the end, I want to have an array with shape (N1,N2,N3,...,Nm,N0).</p>

<p>Any nice ideas?</p>

<blockquote>
  <p>I tried with np.rollaxis, but this seems to be the wrong function.</p>
</blockquote>

<p>No, it's the right function.</p>

<pre><code>x = numpy.rollaxis(x, 0, x.ndim)
</code></pre>

python numpy