Last active
September 5, 2019 08:41
-
-
Save Syncrossus/1a69bdb78add4e83027f82f9c55180b4 to your computer and use it in GitHub Desktop.
Function that transforms scores to ranks : takes a matrix with 2 columns with each row being of the form [object, score] and turns each row into the form [object, rank]. Highest score => rank 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def score2rank(m): | |
""" args: | |
- m, a numpy matrix with 2 columns the 2nd of which should be numeric | |
returns: | |
- m with the second column's numbers switched for ranks | |
example: | |
m = [[a,5.8], return = [[a,2], | |
[b,0.1], [b,5], | |
[c,0.3], [c,3], | |
[d,7.2], [d,1], | |
[e,0.2]] [e,4]] | |
""" | |
m[np.argsort(m[:, 1], axis=0), 1] = [[i] for i in range(m.shape[0], 0, -1)] | |
return m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is released under the .