cogmission cogmission - 7 months ago 71
Python Question

Python Special Colon Inquiry

sortedWinnerIndices = winnerIndices[-numActive:][::-1]

Can someone tell me what is going on here?

is 2048 ints long, Numpy array. I read somewhere that
reverses the result but I still can't figure out how this function selects a subset of winnerIndices?


Break it up into steps. It's equivalent to:

subset = winnerIndices[-numActive:]
sortedWinnerIndices = subset[::-1]

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