megengine.functional.sign

sign(x)[source]

Element-wise sign.

Returns an indication of the sign of a number for each element \(x_i\) of the input tensor \(x\).

Parameters

inp – input tensor. Should have a numeric data type.

Returns

a tensor containing the evaluated result for each element in \(x\). The returned array must have the same data type as \(x\).

Examples

Element-wise sign:

>>> x = Tensor([1, -1, 0])
>>> F.sign(x)
Tensor([ 1 -1  0], dtype=int32, device=xpux:0)