Created
July 22, 2020 16:38
-
-
Save WhatIThinkAbout/d90154f7099065e0d601f30d0579b5e4 to your computer and use it in GitHub Desktop.
a random tie-breaking argmax
This file contains hidden or 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
| # return the index of the largest value in the supplied list | |
| # - arbitrarily select between the largest values in the case of a tie | |
| # (the standard np.argmax just chooses the first value in the case of a tie) | |
| def random_argmax(value_list): | |
| """ a random tie-breaking argmax """ | |
| values = np.asarray(value_list) | |
| return np.argmax(np.random.random(values.shape) * (values==values.max())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment