<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/math_ops.py#L271-L323) |

Returns the index with the largest value across axes of a tensor.

#### View aliases


**Main aliases**

[`tf.argmax`](https://www.tensorflow.org/api_docs/python/tf/math/argmax)

<br />

    tf.math.argmax(
        input,
        axis=None,
        output_type=https://www.tensorflow.org/api_docs/python/tf/dtypes#int64,
        name=None
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Multilayer perceptrons for digit recognition with Core APIs](https://www.tensorflow.org/guide/core/mlp_core) - [Migrate metrics and optimizers](https://www.tensorflow.org/guide/migrate/metrics_optimizers) - [Distributed training with Core APIs and DTensor](https://www.tensorflow.org/guide/core/distribution) - [Introduction to Tensors](https://www.tensorflow.org/guide/tensor) - [Introduction to Variables](https://www.tensorflow.org/guide/variable) | - [Transfer learning with YAMNet for environmental sound classification](https://www.tensorflow.org/tutorials/audio/transfer_learning_audio) - [Transfer learning with TensorFlow Hub](https://www.tensorflow.org/tutorials/images/transfer_learning_with_hub) - [Custom training: walkthrough](https://www.tensorflow.org/tutorials/customization/custom_training_walkthrough) - [Simple audio recognition: Recognizing keywords](https://www.tensorflow.org/tutorials/audio/simple_audio) - [Distributed training with DTensors](https://www.tensorflow.org/tutorials/distribute/dtensor_ml_tutorial) |

In case of identity returns the smallest index.

#### For example:

    A = tf.constant([2, 20, 30, 3, 6])
    tf.math.argmax(A)  # A[2] is maximum in tensor A
    <tf.Tensor: shape=(), dtype=int64, numpy=2>
    B = tf.constant([[2, 20, 30, 3, 6], [3, 11, 16, 1, 8],
                     [14, 45, 23, 5, 27]])
    tf.math.argmax(B, 0)
    <tf.Tensor: shape=(5,), dtype=int64, numpy=array([2, 2, 0, 2, 2])>
    tf.math.argmax(B, 1)
    <tf.Tensor: shape=(3,), dtype=int64, numpy=array([2, 2, 1])>
    C = tf.constant([0, 0, 0, 0])
    tf.math.argmax(C) # Returns smallest index in case of ties
    <tf.Tensor: shape=(), dtype=int64, numpy=0>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `input` | A `Tensor`. |
| `axis` | An integer, the axis to reduce across. Default to 0. |
| `output_type` | An optional output dtype ([`tf.int32`](https://www.tensorflow.org/api_docs/python/tf#int32) or [`tf.int64`](https://www.tensorflow.org/api_docs/python/tf#int64)). Defaults to [`tf.int64`](https://www.tensorflow.org/api_docs/python/tf#int64). |
| `name` | An optional name for the operation. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` of type `output_type`. ||

<br />