Created
October 16, 2017 00:27
-
-
Save aarshtalati/64054aeeca74e9706c2bb87dca16367e to your computer and use it in GitHub Desktop.
An alternative to numpy.argmin()
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 | |
>>> 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