Skip to content

Instantly share code, notes, and snippets.

@aarshtalati
Created October 16, 2017 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarshtalati/64054aeeca74e9706c2bb87dca16367e to your computer and use it in GitHub Desktop.
Save aarshtalati/64054aeeca74e9706c2bb87dca16367e to your computer and use it in GitHub Desktop.
An alternative to numpy.argmin()
>>> import numpy as np
>>> x = np.arange(127, 255, 50)
>>> x
array([127, 177, 227])
>>> x.argmin()
0
>>> x = x[::-1]
>>> x
array([227, 177, 127])
>>> x.argmin()
2
>>>
>>> # an alternative ...
...
>>> x = np.arange(127, 255, 50)
>>> n = range(len(x))
>>> n[x.tolist().index(min(x))]
0
>>> x = x[::-1]
>>> n[x.tolist().index(min(x))]
2
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment