Issue
I'd like to generate an array which contains the positions of the highest integers/floating point numbers to the lowest in another array. For example:
integers = [1,6,8,5]
I want the newly generated array to be:
newArray = [2,1,3,0]
or
floatingPoints = [1.6,0.5,1.1]
would become
newArray = [0,2,1]
Solution
You can use the numpy
function argsort
and then simply reverse the ordering as it gives you ascending rather than descending, by default:
np.argsort(integers)[::-1]
Example:
import numpy as np
integers = np.array([1, 6, 8, 5])
np.argsort(integers)[::-1]
This results in the desired [2, 1, 3, 0]
.
Answered By - statnet22 Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.