1

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Zanam
  • 4,607
  • 13
  • 67
  • 143

1 Answers1

3

You can try, for max of negative:

list(Arr).index(max(Arr[Arr<0]))

In above, Arr[Arr<0] will get all numbers less than 0 or negative and applying max to the list will give max of negative. Then, it can be used with index to get the index of number in list.

And for min of positive:

list(Arr).index(min(Arr[Arr>0]))
niraj
  • 17,498
  • 4
  • 33
  • 48