Python Special Colon Inquiry
<pre><code>sortedWinnerIndices = winnerIndices[-numActive:][::-1]
</code></pre>

<p>Can someone tell me what is going on here? </p>

<p><code>WinnerIndices</code> is 2048 ints long, Numpy array. I read somewhere that <code>[::-1]</code> reverses the result but I still can't figure out how this function selects a subset of winnerIndices?</p>

<p>Break it up into steps. It's equivalent to:</p>

<pre><code>subset = winnerIndices[-numActive:]
sortedWinnerIndices = subset[::-1]
</code></pre>

<p>The first statement selects the last <code>numActive</code> elements in the array. The second line reverses it. So when you combine them you get the last <code>numActive</code> elements in the reverse order from the original array.</p>

python numpy operator-keyword colon