| View source on GitHub | 
Computes the absolute value of a tensor.
tf.math.abs(
    x, name=None
)
  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}\).
# 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]])>
  
| Args | |
|---|---|
| x | A TensororSparseTensorof typefloat16,float32,float64,int32,int64,complex64orcomplex128. | 
| name | A name for the operation (optional). | 
| Returns | |
|---|---|
| A TensororSparseTensorof the same size, type and sparsity asx, with absolute values. Note, forcomplex64orcomplex128input, the returnedTensorwill be of typefloat32orfloat64, respectively.If  | 
    © 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
    https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/math/abs