Assuming I have a 2d numpy array indicating the probabilities for m samples in n classes (probabilities add up to 1 for each sample).
Assuming that each sample can only be in one category, I want to create a new array with the same shape as the original, but only with binary values indicating which class had the highest probability.
Example:
[[0.2, 0.3, 0.5], [0.7, 0.1, 0.1]]
should be converted to:
[[0, 0, 1], [1, 0, 0]]
It seems that amax is already doing almost what I want, but instead of indexes, I need a matrix of indicators, as described above.
It seems simple, but somehow I can't figure it out using the standard numpy functions. Of course, I could use regular python loops, but it seems like there should be an easier way.
If multiple classes have the same probability, I would prefer a solution that selects only one of the classes (I don't care, in this case).
Thanks!
source share