tf.math.argmax
Stay organized with collections
Save and categorize content based on your preferences.
Returns the index with the largest value across axes of a tensor.
tf.math.argmax(
input,
axis=None,
output_type=tf.dtypes.int64
,
name=None
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
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>
Args |
input
|
A Tensor .
|
axis
|
An integer, the axis to reduce across. Default to 0.
|
output_type
|
An optional output dtype (tf.int32 or tf.int64 ). Defaults
to tf.int64 .
|
name
|
An optional name for the operation.
|
Returns |
A Tensor of type output_type .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.math.argmax\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L262-L296) |\n\nReturns the index with the largest value across axes of a tensor.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.argmax`](https://www.tensorflow.org/api_docs/python/tf/math/argmax)\n\n\u003cbr /\u003e\n\n tf.math.argmax(\n input,\n axis=None,\n output_type=../../tf/dtypes#int64,\n name=None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [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) |\n\nIn case of identity returns the smallest index.\n\n#### For example:\n\n A = tf.constant([2, 20, 30, 3, 6])\n tf.math.argmax(A) # A[2] is maximum in tensor A\n \u003ctf.Tensor: shape=(), dtype=int64, numpy=2\u003e\n B = tf.constant([[2, 20, 30, 3, 6], [3, 11, 16, 1, 8],\n [14, 45, 23, 5, 27]])\n tf.math.argmax(B, 0)\n \u003ctf.Tensor: shape=(5,), dtype=int64, numpy=array([2, 2, 0, 2, 2])\u003e\n tf.math.argmax(B, 1)\n \u003ctf.Tensor: shape=(3,), dtype=int64, numpy=array([2, 2, 1])\u003e\n C = tf.constant([0, 0, 0, 0])\n tf.math.argmax(C) # Returns smallest index in case of ties\n \u003ctf.Tensor: shape=(), dtype=int64, numpy=0\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | A `Tensor`. |\n| `axis` | An integer, the axis to reduce across. Default to 0. |\n| `output_type` | An optional output dtype ([`tf.int32`](../../tf#int32) or [`tf.int64`](../../tf#int64)). Defaults to [`tf.int64`](../../tf#int64). |\n| `name` | An optional name for the operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` of type `output_type`. ||\n\n\u003cbr /\u003e"]]