ML Foundations
Gather the winning score for each NumPy row
Use an explicit argmax axis and take_along_axis to keep row winners aligned with their scores.

Evidence and testing
Review record: Tensor Almanac automated evidence gate (no independent human review). Example versions, recorded outputs and limitations appear below.
Choose the axis before choosing a winner
When each row contains scores for a different observation, the usual task is to find one winning column per row. NumPy argmax without an axis instead searches the flattened array and returns one index for the whole matrix. Specify axis 1 to reduce across columns independently. [1]
The returned indices are column positions, not the winning scores themselves. Preserving a length-one column dimension makes those indices suitable for gathering one value from each corresponding row.
References: [1]
Keep a dimension and gather along it
Run python examples/numpy_rowwise_argmax.py. Its two rows have their largest scores in different columns. The default flattened argmax returns the single index 3. With axis 1 and keepdims enabled, the winner column indices are 1 and 0 in a two-row, one-column array. [1]
Pass those indices to take_along_axis with the same axis. It gathers the score at each row-specific column rather than applying the full list of columns to every row. The result contains 0.8 and 0.9 and retains a shape of two rows by one column. [2]
The example prints a flattened view only for readability. The gathered result itself stays two-dimensional; use a deliberate squeeze or reshape if downstream code expects a vector. Assertions verify the fixture indices and selected values.
Executed with Python 3.12.14 and NumPy 2.3.5; stdout and checksum are in private evidence.
import numpy as np
scores = np.array([[0.2, 0.8, 0.1], [0.9, 0.3, 0.4]])
flat_index = np.argmax(scores)
winners = np.argmax(scores, axis=1, keepdims=True)
selected = np.take_along_axis(scores, winners, axis=1)
print('flattened index:', int(flat_index))
print('winner columns:', winners.ravel().tolist())
print('selected scores:', selected.ravel().tolist())
print('selected shape:', selected.shape)
assert winners.ravel().tolist() == [1, 0]
assert selected.ravel().tolist() == [0.8, 0.9]
Recorded output
flattened index: 3 winner columns: [1, 0] selected scores: [0.8, 0.9] selected shape: (2, 1)
Define ties and invalid scores separately
For equal maxima, NumPy argmax returns the first occurrence along the reduced axis. If your application needs another tie policy, specify and test it rather than interpreting this example as a general ranking rule. [1]
This small finite two-dimensional fixture has one maximum per row. It does not handle missing scores, all-NaN rows, empty axes or a production throughput comparison. Check those conditions before reduction; a separate missing-row policy is needed when no candidate is valid.