While there are some interesting conversations about numpy.argmin() function’s performance (e.g. here, here and here), I want to stay away from making any comments. I also do not claim that my alternative is necessarily faster or slower than np.argmin() or np.argmax(), an alternative is an alternative.
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 | |
>>> |