Skip to content

Instantly share code, notes, and snippets.

@WhatIThinkAbout
Created July 22, 2020 16:38
Show Gist options
  • Select an option

  • Save WhatIThinkAbout/d90154f7099065e0d601f30d0579b5e4 to your computer and use it in GitHub Desktop.

Select an option

Save WhatIThinkAbout/d90154f7099065e0d601f30d0579b5e4 to your computer and use it in GitHub Desktop.
a random tie-breaking argmax
# 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