mindspore.numpy.absolute

mindspore.numpy.absolute(x, dtype=None)[源代码]

Calculates the absolute value element-wise.

说明

Numpy arguments out, where, casting, order, subok, signature, and extobj are not supported. Currently the backend kernel only supports float calculation, if the input is not a float, then it will be casted to mstype.float32 and casted back.

参数
  • x (Tensor) – Tensor to be used for calculation.

  • dtype (mindspore.dtype, optional) – Defaults to None. Overrides the dtype of the output Tensor.

返回

Tensor.

异常

TypeError – If input arguments have types not specified above.

Supported Platforms:

Ascend GPU CPU

样例

>>> import mindspore.numpy as np
>>> x = np.asarray([1, 2, 3, -4, -5], np.float32)
>>> output = np.absolute(x)
>>> print(output)
[1. 2. 3. 4. 5.]