tf.math.abs
Stay organized with collections
Save and categorize content based on your preferences.
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
. All
elements in x
must be complex numbers of the form \(a + bj\). The
absolute value is computed as \( \sqrt{a^2 + b^2}\). For example:
x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]])
tf.abs(x) # [5.25594902, 6.60492229]
Args |
x
|
A Tensor or SparseTensor of type float16 , float32 , float64 ,
int32 , int64 , complex64 or complex128 .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor or SparseTensor 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.
If x is a SparseTensor , returns
SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)
|
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.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.math.abs\n\n|---------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/math/abs) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/ops/math_ops.py#L248-L281) |\n\nComputes the absolute value of a tensor.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.abs`](/api_docs/python/tf/math/abs)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.abs`](/api_docs/python/tf/math/abs), [`tf.compat.v1.math.abs`](/api_docs/python/tf/math/abs)\n\n\u003cbr /\u003e\n\n tf.math.abs(\n x, name=None\n )\n\nGiven a tensor of integer or floating-point values, this operation returns a\ntensor of the same type, where each element contains the absolute value of the\ncorresponding element in the input.\n\nGiven a tensor `x` of complex numbers, this operation returns a tensor of type\n`float32` or `float64` that is the absolute value of each element in `x`. All\nelements in `x` must be complex numbers of the form \\\\(a + bj\\\\). The\nabsolute value is computed as \\\\( \\\\sqrt{a\\^2 + b\\^2}\\\\). For example: \n\n x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]])\n tf.abs(x) # [5.25594902, 6.60492229]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|----------------------------------------------------------------------------------------------------------------------|\n| `x` | A `Tensor` or `SparseTensor` of type `float16`, `float32`, `float64`, `int32`, `int64`, `complex64` or `complex128`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` or `SparseTensor` 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. \u003cbr /\u003e If `x` is a `SparseTensor`, returns `SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)` ||\n\n\u003cbr /\u003e"]]