using numpy.where on multidimensional arrays

Viewed 606

I have a 2D array, each row represents an output of a classifier that classifies some input to 3 categories (array size is 1000 * 3) :

0.3 0.3 0.3
0.3 0.3 1.0
1.0 0.3 0.3
0.3 0.3 0.3
0.3 1.0 0.3
...

I want to get a list of all the inputs that the classifier is "not sure" about them. And I'm defining "not sure" as no category is above 0.8.

To solve it I use :

np.where(model1_preds.max(axis=1) < 0.8)

This works great.

But now I have 6 classifiers (that have analyzed the same inputs in the same order), and an array 6 * 1000 * 3 representing their results.

I want to find 2 things:

  1. All the inputs that at least one classifier was "not sure" about.
  2. All the inputs that all the classifier were "not sure" about.

I assume the general direction is something like this :

np.stack(np.where(model_preds.max(axis=1) < 0.8) for model_preds in all_preds)

But it won't work because python don't know what I mean in the for loop.

2 Answers
Related