mindspore.ops.abs

mindspore.ops.abs(x)[source]

Returns absolute value of a tensor element-wise.

\[out_i = |x_i|\]
Parameters

x (Tensor) – The input tensor. The shape of tensor is \((N,*)\) where \(*\) means, any number of additional dimensions.

Returns

Tensor, has the same shape as the x.

Raises

TypeError – If x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.array([-1.0, 1.0, 0.0]), mindspore.float32)
>>> output = ops.abs(x)
>>> print(output)
[1. 1. 0.]