Join the newly launched Discord
community for real-time discussions, peer support, and direct interaction with the Meridian team!
meridian.backend.absolute
Stay organized with collections
Save and categorize content based on your preferences.
Computes the absolute value of a tensor.
meridian
.
backend
.
absolute
(
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}\).
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
]])
>
A Tensor
or SparseTensor
of type float16
, float32
, float64
, int32
, int64
, complex64
or complex128
.
A name for the operation (optional).
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. 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 2025-08-22 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 2025-08-22 UTC."],[],[],null,["# meridian.backend.absolute\n\n\u003cbr /\u003e\n\nComputes the absolute value of a tensor. \n\n meridian.backend.absolute(\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`. For\na complex number \\\\(a + bj\\\\), its absolute value is computed as\n\\\\(\\\\sqrt{a\\^2 + b\\^2}\\\\).\n\n#### For example:\n\n \u003e\u003e\u003e # real number\n \u003e\u003e\u003e x = tf.constant([-2.25, 3.25])\n \u003e\u003e\u003e tf.abs(x)\n \u003ctf.Tensor: shape=(2,), dtype=float32,\n numpy=array([2.25, 3.25], dtype=float32)\u003e\n\n \u003e\u003e\u003e # complex number\n \u003e\u003e\u003e x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]])\n \u003e\u003e\u003e tf.abs(x)\n \u003ctf.Tensor: shape=(2, 1), dtype=float64, numpy=\n array([[5.25594901],\n [6.60492241]])\u003e\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` 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. \u003cbr /\u003e If `x` is a `SparseTensor`, returns `SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)` ||\n\n\u003cbr /\u003e"]]