<p dir="auto"><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.rollaxis.html#numpy.rollaxis" rel="nofollow"><code class="notranslate">rollaxis</code></a> has an optional <code class="notranslate">start</code> parameter that, if specified, moves the axis to the position <em>before</em> <code class="notranslate">start</code>. Or, as the documentation puts it</p>
<blockquote>
<p dir="auto">The axis is rolled until it lies before this position. The default, 0, results in a “complete” roll.</p>
</blockquote>
<p dir="auto">(Just by the way: The last sentence is unclear. What's a "complete roll"? Better be explicit: <em>The default, 0, moves the axis to the beginning.</em>)</p>
<p dir="auto">E.g.,</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="a = numpy.ones((1, 2, 3, 4))
b = numpy.rollaxis(a, 0, 3)
print(b.shape)"><pre class="notranslate"><span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">numpy</span>.<span class="pl-en">ones</span>((<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>))
<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">numpy</span>.<span class="pl-en">rollaxis</span>(<span class="pl-s1">a</span>, <span class="pl-c1">0</span>, <span class="pl-c1">3</span>)
<span class="pl-en">print</span>(<span class="pl-s1">b</span>.<span class="pl-s1">shape</span>)</pre></div>
<p dir="auto">moves the axis at position 0 to the place before position 3, and hence the above will print <code class="notranslate">(2, 3, 1, 4)</code>.</p>
<p dir="auto">This <em>before</em> logic results in the fact that there are always two <code class="notranslate">start</code> indices which will do exactly the same thing, namely <code class="notranslate">numpy.rollaxis(a, i, i)</code> and <code class="notranslate">numpy.rollaxis(a, i, i+1)</code> – nothing. As a trade-off for this duplication, what you can't seem to do is to move the axis in the <em>last</em> place, since there is no axis that comes after.</p>
<p dir="auto">I used the word <em>seem</em>, because you can actually do <code class="notranslate">numpy.rollaxis(a, i, len(a.shape))</code> to insert it axis <code class="notranslate">i</code> before the imaginary axis at position <code class="notranslate">len(a.shape)</code>. This is not explicitly documented.</p>
<p dir="auto">On top of that, why is the parameter called <code class="notranslate">start</code>? I have no idea.</p>
<hr>
<p dir="auto"><strong>Edit</strong> The following suggestion is actually just what <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.moveaxis.html" rel="nofollow"><code class="notranslate">moveaxis</code></a> does.</p>
<p dir="auto">A more consistent approach would be to have a parameter <code class="notranslate">target</code> (or <code class="notranslate">target_position</code>) that can be used to specify the position of axis <code class="notranslate">i</code> after the roll. E.g.,</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="a = numpy.ones((1, 2, 3, 4))
numpy.rollaxis(a, 0, target=0).shape  # (1, 2, 3, 4)
numpy.rollaxis(a, 0, target=1).shape  # (2, 1, 3, 4)
numpy.rollaxis(a, 0, target=len(a.shape))  # error
numpy.rollaxis(a, 0, target=-1).shape  # (2, 3, 4, 1)"><pre class="notranslate"><span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">numpy</span>.<span class="pl-en">ones</span>((<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>))
<span class="pl-s1">numpy</span>.<span class="pl-en">rollaxis</span>(<span class="pl-s1">a</span>, <span class="pl-c1">0</span>, <span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-c1">0</span>).<span class="pl-s1">shape</span>  <span class="pl-c"># (1, 2, 3, 4)</span>
<span class="pl-s1">numpy</span>.<span class="pl-en">rollaxis</span>(<span class="pl-s1">a</span>, <span class="pl-c1">0</span>, <span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-s1">shape</span>  <span class="pl-c"># (2, 1, 3, 4)</span>
<span class="pl-s1">numpy</span>.<span class="pl-en">rollaxis</span>(<span class="pl-s1">a</span>, <span class="pl-c1">0</span>, <span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-en">len</span>(<span class="pl-s1">a</span>.<span class="pl-s1">shape</span>))  <span class="pl-c"># error</span>
<span class="pl-s1">numpy</span>.<span class="pl-en">rollaxis</span>(<span class="pl-s1">a</span>, <span class="pl-c1">0</span>, <span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-c1">-</span><span class="pl-c1">1</span>).<span class="pl-s1">shape</span>  <span class="pl-c"># (2, 3, 4, 1)</span></pre></div>
<p dir="auto">The last example shows how to move the first axis to the last position without recalling <code class="notranslate">len(a.shape)</code>.</p>
<p dir="auto">In Anaconda3(numpy 1.90).</p>
<h2 dir="auto">I think there are something wrong to the results of the matrix inverse function below.</h2>
<p dir="auto">import numpy as np<br>
a = np.mat('1,2,3;4,5,6;7,8,9')</p>
<p dir="auto">print(a.I.I)</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">G:\Anaconda3\python.exe C:/Users/4078/test/chap3.22.py<br>
[[ 2.38095238  3.0952381   3.80952381]<br>
[ 2.85714286  3.21428571  3.57142857]</p>
<h2 dir="auto">[ 3.33333333  3.33333333  3.33333333]]</h2>
<p dir="auto">And if you change a = np.mat('1,2,3;4,5,6;7,8,9') to a = np.mat('1,2,3;4,5,6;7,8,9.1') or any other number (not Singular matrix)the result would be correct.</p>
</blockquote>
</blockquote>
</blockquote>