Hi I'm trying to map an array of numbers to their ranks. So for example [2,5,3] would become [0,2,1].
I'm currently using np.where to lookup the rank in an array, but this is proving to take a very long time as I have to do this for a very large array (over 2 million datapoints).
If anyone has any suggestions on how I could achieve this, I'd greatly appreciate it!
[EDIT] This is what the code to change a specific row currently looks like:
def change_nodes(row):
a = row
new_a = node_map[node_map[:,1] == a][0][0]
return new_a
[EDIT 2] Duplicated numbers should additionally have the same rank
[EDIT 3] Additionally, unique numbers should only count once towards the ranking. So for example, the rankings for this list [2,3,3,4,5,7,7,7,7,8,1], would be:
{1:0, 2:1, 3:2, 4:3, 5:4, 7:5, 8:6 }