-1

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]

1 Answers1

0

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].

statnet22
  • 444
  • 2
  • 13