What is argmax? Meaning, examples, argmax vs max

Argmax is the input at which a function reaches its largest value. Max is that largest value itself. For scores A = 0.2, B = 0.9 and C = 0.6, max is 0.9 and argmax is B.

In code the input is usually a position: np.argmax([10, 45, 20, 45]) returns 1, the index of the first 45. In a classifier argmax returns a class label, in reinforcement learning an action, and in model fitting a parameter vector.

The two answers have different types, which is where reading mistakes start. A value cannot choose an action, and a chosen action cannot be differentiated as if it were a score. Reading the output type before manipulating an equation keeps the paper's data flow intact.

Argmax vs max on one table

Imagine a table mapping each candidate to a score. The candidates form the domain and the scores form the output of an objective function. Max searches the score column. Argmax searches the candidate column using the score column as its ranking rule.

In the three-candidate example above, max reads 0.9 from the score column and argmax reads B from the candidate column. Saying argmax equals 0.9 swaps the objective value for the input that produced it.

Read the subscript aloud. Max over x of f(x) means find the largest value produced as x varies. Argmax over x of f(x) means find the x values at which that largest value is attained.

The open Convex Optimization book by Boyd and Vandenberghe distinguishes an optimal value from an optimal point. That typed distinction is the foundation beneath max and argmax notation.

Max returns the winning value

The maximum of a finite list is the member no other member exceeds. If the list is 2, 7, and 4, the maximum is 7. The operator has discarded which position held that value unless the surrounding system retains the mapping.

In reinforcement learning, max over actions of Q(s,a) returns the highest action value available in state s. Its output has the same kind of units as Q, often expected discounted reward. It is not itself an action.

In a probability model, max may return the highest assigned probability or the largest logit depending on what enters the operator. The input expression, not the word max, determines the scale and interpretation of the result.

Argmax returns the winning address

Arg is short for argument, meaning the input supplied to a function. Argmax returns the input or inputs that make the function as large as possible. Its output belongs to the search domain, not necessarily to the real numbers.

For a classifier, argmax over class labels of p(y given x) returns the predicted label. For a policy, argmax over actions of Q(s,a) returns a greedy action. For model fitting, argmax over parameters of a likelihood returns an optimizing parameter setting.

Sutton and Barto's Reinforcement Learning textbook uses maximizing action selection throughout value-based methods. Its equations make the output contract concrete: the values rank actions, while the policy ultimately needs an action.

Superscript star often labels the returned optimizer, as in x star equals argmax of f. The star is not what performs optimization. It only names the selected object, and in other contexts a star can mean conjugate, adjoint, or another special reference.

Type checking catches the swap

Write a two-column ledger before reading a dense objective. Put every candidate in the left column and its score in the right. Then label each downstream operation with the column it requires. A selector needs a candidate. A comparison threshold usually needs a score.

If x is a vector in R to the d, argmax over x may return a vector. If the search domain is a set of token sequences, the result may be a whole sequence. The fact that the objective is scalar does not make the optimizer scalar.

Shapes can reveal the same error in code-oriented papers. A class-score tensor may have one score per class, while an argmax along the class axis removes that axis and yields integer indices. The axis is part of the operator's meaning.

The Mathematics for Machine Learning text develops optimization as choosing parameters from a domain to minimize or maximize an objective. That domain-to-value map is the simplest mental model for the two operators.

Argmax in NumPy and PyTorch

In code, argmax returns a position, and the axis argument decides what that position indexes: for scores = [[0.1, 0.7, 0.2], [0.5, 0.3, 0.2]], np.argmax(scores) with no axis flattens the array and returns 1, an index into all six values rather than a row or a column.

np.argmax(scores, axis=1) returns [1, 0]: the winning column in each row. That is a classifier's prediction step, one class index per example. torch.argmax(logits, dim=-1) does the same along the last axis of a batch of logits.

NumPy and PyTorch break ties by returning the first maximal index, as both libraries' documentation states, and both return integer indices. The torch.argmax reference also covers dim and keepdim. A predicted label carries no gradient back to the scores, which is why training applies a loss to probabilities instead.

Argmax picks the next token in greedy decoding

A language model emits one logit per vocabulary entry at every step. Greedy decoding appends the argmax of those logits. Softmax preserves order, so the argmax of the logits and the argmax of the probabilities are the same token, and greedy decoding can skip the softmax.

Sampling replaces argmax with a draw from the softmax distribution. A lower temperature concentrates that distribution on the argmax token. As temperature approaches zero, its probability approaches one whenever one logit is strictly largest. The Sampling Playground shows the collapse as you move temperature, top-k and top-p.

Ties make argmax set-valued

If A and B both score 0.9, max remains the single value 0.9. Argmax is mathematically the set containing A and B. Writing only A silently adds a tie-breaking rule that the objective did not supply.

Software libraries often return the first maximizing index, a deterministic implementation choice. A policy might break ties randomly. A proof may permit any maximizer. These behaviors are not interchangeable, so inspect the algorithm or library contract.

A maximum also may not exist. A supremum can describe the least upper bound even when no point attains it. Introductory ML formulas often assume a finite candidate set or an objective and domain where an optimizer exists, but research proofs state these conditions carefully.

The ML Math lesson on reading argmax and argmin from tables and graphs practises the same reading on plotted functions, including ties and the difference between an optimizer and its value.

Use the choice-versus-value sandbox

Move the three candidate scores below. Predict both outputs before reading them. Then create a tie. The visualization keeps the height and address visible at once so the distinction remains mechanical rather than verbal.

Notice that changing a losing score may change neither answer. Raising it past the leader changes both. Matching the leader changes the argmax set without changing the max value. Those three cases are useful tests for any explanation of the operators.

After the sandbox, compare the semantic entries for argmax and maximum. A symbol page should record output type and tie behavior, not only pronunciation.

Where the simple picture stops

The bar chart uses a finite discrete domain. Optimization over continuous parameters may require calculus, convexity, numerical search, or approximation. Argmax still names the desired input, but computing it can be the central difficulty of the paper.

Argmax is not ordinarily differentiable as a discrete selection step. Softmax, sampling, straight-through estimators, and continuous relaxations address different training needs, but none is simply argmax with friendlier typography. Each changes the mechanism or gradient story.

A paper may also write arg top-k, beam search, or approximate maximization when one winner is insufficient or exact search is infeasible. Preserve qualifiers such as approximate and constrained because they change what claim the equation makes.

Frequently asked questions

What is argmax used for

Choosing a predicted class from classifier scores, a greedy action from Q-values, the next token in greedy decoding, and the parameters that maximize a likelihood. In each case argmax returns the choice, and max would return its score.

Is argmax always one item

No. Several inputs can tie for the largest objective value. Pure mathematics usually treats argmax as a set. An implementation may apply a documented tie-breaker and return one element.

What is the difference between argmax and softmax

Argmax returns one position, the index of the largest input. Softmax returns a probability for every input and keeps their order, so its largest weight sits at the argmax. Lowering the temperature concentrates softmax around that position, but the outputs stay different types: an integer index against a vector of weights that sum to one.

What does argmin change

Argmin returns the input producing the smallest objective. The value-versus-choice distinction is identical. Loss functions are usually minimized, while rewards and likelihoods are often maximized.

Carry the output type forward

Practice locating domains, objectives, and outputs in the Math Decoder curriculum, then apply the same ledger method to real equations in Fanout Daily.

When you encounter either operator, write two words in the margin: value for max, choice for argmax. Then check ties, constraints, axes, and approximations before carrying the result into the next line.