<p dir="auto">[This isn't actually a 1.10 blocker, but hopefully it will be resolved trivially before that so sticking the tag on so it doesn't get lost.]</p>
<p dir="auto"><a href="http://thread.gmane.org/gmane.comp.python.numeric.general/60520" rel="nofollow">http://thread.gmane.org/gmane.comp.python.numeric.general/60520</a></p>
<p dir="auto">the function argsort() returns a wrong indice that would sort an array.<br>
for example:</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">from numpy import *<br>
a=array([4,2,3,1])<br>
argsort(a)<br>
array([3, 1, 2, 0], dtype=int64)</p>
</blockquote>
</blockquote>
</blockquote>
<h3 dir="auto">so this is right, it returned the sorted index. but the follow example is wrong:</h3>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">a=array([4,2,3])<br>
argsort(a)<br>
array([1, 2, 0], dtype=int64)</p>
</blockquote>
</blockquote>
</blockquote>
<h3 dir="auto">the right index should be array([2,0,1]),and the follow example is also wrong:</h3>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">a=array([5,1,4,3,2])<br>
argsort(a)<br>
array([1, 4, 3, 2, 0], dtype=int64)</p>
</blockquote>
</blockquote>
</blockquote>
<h3 dir="auto">the right index should be array([4,0,3,2,1]),and the follow example is also wrong:</h3>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">a=array([7,1,5,2,4,6,3])<br>
argsort(a)<br>
array([1, 3, 6, 4, 2, 5, 0], dtype=int64)</p>
</blockquote>
</blockquote>
</blockquote>
<h3 dir="auto">the right index should be array([6,0,4,1,3,5,2]),so I find a error rule that function argsort() will display the wrong index when an array that starts with a maximum and has an odd number of elements.</h3>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt;from numpy import *
&gt;&gt;&gt; a=array([4,2,3,1])
&gt;&gt;&gt; argsort(a)
array([3, 1, 2, 0], dtype=int64)
### so this is right, it returned the sorted index. but the follow example is wrong:
&gt;&gt;&gt; a=array([4,2,3])
&gt;&gt;&gt; argsort(a)
array([1, 2, 0], dtype=int64)
### the right index should be array([2,0,1]),and the follow example is also wrong:

&gt;&gt;&gt; a=array([5,1,4,3,2])
&gt;&gt;&gt; argsort(a)
array([1, 4, 3, 2, 0], dtype=int64)
### the right index should be array([4,0,3,2,1]),and the follow example is also wrong:
&gt;&gt;&gt; a=array([7,1,5,2,4,6,3])
&gt;&gt;&gt; argsort(a)
array([1, 3, 6, 4, 2, 5, 0], dtype=int64)"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span><span class="pl-k">from</span> <span class="pl-s1">numpy</span> <span class="pl-k">import</span> <span class="pl-c1">*</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a</span><span class="pl-c1">=</span><span class="pl-en">array</span>([<span class="pl-c1">4</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">1</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-en">argsort</span>(<span class="pl-s1">a</span>)
<span class="pl-en">array</span>([<span class="pl-c1">3</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">0</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int64</span>)
<span class="pl-c">### so this is right, it returned the sorted index. but the follow example is wrong:</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a</span><span class="pl-c1">=</span><span class="pl-en">array</span>([<span class="pl-c1">4</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-en">argsort</span>(<span class="pl-s1">a</span>)
<span class="pl-en">array</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">0</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int64</span>)
<span class="pl-c">### the right index should be array([2,0,1]),and the follow example is also wrong:</span>

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a</span><span class="pl-c1">=</span><span class="pl-en">array</span>([<span class="pl-c1">5</span>,<span class="pl-c1">1</span>,<span class="pl-c1">4</span>,<span class="pl-c1">3</span>,<span class="pl-c1">2</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-en">argsort</span>(<span class="pl-s1">a</span>)
<span class="pl-en">array</span>([<span class="pl-c1">1</span>, <span class="pl-c1">4</span>, <span class="pl-c1">3</span>, <span class="pl-c1">2</span>, <span class="pl-c1">0</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int64</span>)
<span class="pl-c">### the right index should be array([4,0,3,2,1]),and the follow example is also wrong:</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">a</span><span class="pl-c1">=</span><span class="pl-en">array</span>([<span class="pl-c1">7</span>,<span class="pl-c1">1</span>,<span class="pl-c1">5</span>,<span class="pl-c1">2</span>,<span class="pl-c1">4</span>,<span class="pl-c1">6</span>,<span class="pl-c1">3</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-en">argsort</span>(<span class="pl-s1">a</span>)
<span class="pl-en">array</span>([<span class="pl-c1">1</span>, <span class="pl-c1">3</span>, <span class="pl-c1">6</span>, <span class="pl-c1">4</span>, <span class="pl-c1">2</span>, <span class="pl-c1">5</span>, <span class="pl-c1">0</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int64</span>)</pre></div>

<h3 dir="auto">Error message:</h3>


<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">Numpy 1.13.3/Python 3.5.2</p>

<p dir="auto">1.13.3 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)]</p>