|---|
| [![](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#L389-L433) |

Computes the absolute value of a tensor.

#### View aliases


**Main aliases**

[`tf.abs`](https://www.tensorflow.org/api_docs/python/tf/math/abs)
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

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

<br />

    tf.math.abs(
        x, name=None
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Training checkpoints](https://www.tensorflow.org/guide/checkpoint) - [Matrix approximation with Core APIs](https://www.tensorflow.org/guide/core/matrix_core) - [Estimators](https://www.tensorflow.org/guide/estimator) - [Better performance with tf.function](https://www.tensorflow.org/guide/function) - [TF-NumPy Type Promotion](https://www.tensorflow.org/guide/tf_numpy_type_promotion) | - [CycleGAN](https://www.tensorflow.org/tutorials/generative/cyclegan) - [Neural style transfer](https://www.tensorflow.org/tutorials/generative/style_transfer) - [Simple audio recognition: Recognizing keywords](https://www.tensorflow.org/tutorials/audio/simple_audio) - [pix2pix: Image-to-image translation with a conditional GAN](https://www.tensorflow.org/tutorials/generative/pix2pix) - [Integrated gradients](https://www.tensorflow.org/tutorials/interpretability/integrated_gradients) |

Given a tensor of integer or floating-point values, this operation returns a
tensor of the same type, where each element contains the absolute value of the
corresponding element in the input.

Given a tensor `x` of complex numbers, this operation returns a tensor of type
`float32` or `float64` that is the absolute value of each element in `x`. For
a complex number \\(a + bj\\), its absolute value is computed as
\\(\\sqrt{a\^2 + b\^2}\\).

#### For example:

    # real number
    x = tf.constant([-2.25, 3.25])
    tf.abs(x)
    <tf.Tensor: shape=(2,), dtype=float32,
    numpy=array([2.25, 3.25], dtype=float32)>

    # complex number
    x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]])
    tf.abs(x)
    <tf.Tensor: shape=(2, 1), dtype=float64, numpy=
    array([[5.25594901],
           [6.60492241]])>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | A `Tensor` or `SparseTensor` of type `float16`, `float32`, `float64`, `int32`, `int64`, `complex64` or `complex128`. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` or `SparseTensor` of the same size, type and sparsity as `x`, with absolute values. Note, for `complex64` or `complex128` input, the returned `Tensor` will be of type `float32` or `float64`, respectively. <br /> If `x` is a `SparseTensor`, returns `SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)` ||

<br />