4

I'm trying to get the indices of the minimum values in array, such as:

ind = np.where((arr == arr.min()))

I'd like to modify this so that I can ignore a specific value. e.g:

ind = np.where((arr == arr[arr != value].min()))

The above solution is ok, but can it be done better?

1
  • meaning faster? or less memory use? ... What size are your arrays? Commented Mar 21, 2014 at 13:08

2 Answers 2

3

You can create a masked array and then use np.where() on it:

m = np.ma.masked_array(a, mask=(a==value))
np.where(m, m==m.min())

giving what you want.

Sign up to request clarification or add additional context in comments.

Comments

2

use numpys argmin()

ind= np.argmin(arr[arr!=value])

1 Comment

argmin returns only the first index.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.