mindspore.numpy.sign

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

Returns an element-wise indication of the sign of a number.

The sign function returns -1 if x < 0, 0 if x == 0, 1 if x > 0. nan is returned for nan inputs.

说明

Numpy arguments out, where, casting, order, subok, signature, and extobj are not supported. Complex inputs are not supported now. On Ascend, integer inputs are not supported.

参数
返回

The sign of x. This is a tensor or a scalar when x is a scalar.

异常

TypeError – If dtype of the input is not in the given types or the input can not be converted to tensor.

Supported Platforms:

Ascend GPU CPU

样例

>>> import mindspore.numpy as np
>>> output = np.sign(np.array([-1., 0., 1., 1.2]))
>>> print(output)
[-1.  0.  1.  1.]