mindspore.mint.abs

View Source On Gitee
mindspore.mint.abs(input)[source]

Returns absolute value of a tensor element-wise.

\[out_i = |input_i|\]
Parameters

input (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 input.

Raises

TypeError – If input is not a Tensor.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> input = Tensor(np.array([-1.0, 1.0, 0.0]), mindspore.float32)
>>> output = mint.abs(input)
>>> print(output)
[1. 1. 0.]