abs

paddle. abs ( x, name=None ) [source]

Perform elementwise abs for input x.

\[out = |x|\]
Parameters
  • x (Tensor) – The input Tensor with data type int32, int64, float16, float32 and float64.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Tensor.A Tensor with the same data type and shape as \(x\).

Examples

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.abs(x)
>>> print(out)
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.40000001, 0.20000000, 0.10000000, 0.30000001])