Numpy reverse keras to_categorical Numpy reverse keras to_categorical numpy numpy

Numpy reverse keras to_categorical


Simple.

numpy.argmax(a, axis=None, out=None)

This returns the indices of the maximum values along an axis.


Adding to MazeRunner09's answer. If you used to_categorical from keras, you will have a list and can use a list comprehension over the entire one-hot encoded list:

y_classes = [np.argmax(y, axis=None, out=None) for y in y_test]


No need to do list comprehension. Simply

numpy.argmax(a, axis=1)

will find argmax in each row for all rows