Signature
np.argmax(a, axis=None)What it does
np.argmax finds the position of the maximum along an axis. For a matrix of class scores it turns each row into the predicted class index, which is the usual bridge between probabilities and labels.
Parameters
aarray_like- Values to search.
axisint, optionaloptional- Axis to reduce; default flattens the input.
Returns
ndarray or int
Example
pythonnp.argmax example
import numpy as np
scores = np.array([[0.1, 0.7, 0.2], [0.8, 0.1, 0.1]])
print(np.argmax(scores, axis=1))Output
[1 0]
Watch out for
- Ties return the first maximum, so do not rely on a stable tie policy.
- For calibrated probabilities use argmax on the probability matrix, not raw scores.