I have an array as follows:
import numpy as np
Arr = np.array([-10, -8, -8, -6, -2, 2, 4, 19])
How do I find the index
of largest negative and smallest positive number?
i.e in the above example index of -2 and 2.
I have an array as follows:
import numpy as np
Arr = np.array([-10, -8, -8, -6, -2, 2, 4, 19])
How do I find the index
of largest negative and smallest positive number?
i.e in the above example index of -2 and 2.
You can try, for max of negative:
In above,
Arr[Arr<0]
will get all numbers less than 0 or negative and applyingmax
to the list will give max of negative. Then, it can be used withindex
to get the index of number in list.And for min of positive: