I am given an array containing both positive and negative numbers.
import numpy as np
arr = np.array([-10.2, -5.3, -2.1, 0, 1.2, 3.4])
I would like to find the index corresponding to the maximum negative number and to a minimum positive number. In the above, my expected outcome is 2
and 4
. Is there any numpy
trick to achieve this? I have found a solution in this link, but I would like to know how this could be done through numpy
functions:
Finding index of largest negative and smallest positive element in array