I'm working with python 3 in Jupyter Notebook.
Imagine I have:
import numpy as np
q = np.array([5, 2, 6, 7, 2])
I now want to find the indices of the minima of the array; in this case the numbers 1 and 4.
I tried using:
np.argmin(q)
This gives:
1
Unfortunately np.argmin() only works when there is only one minimum. How do I find the index of the other minimum?
Use np.where()
:
np.where(q == q.min())[0]
Result :
array([1, 4])