megengine.functional.sign¶

sign(x)[源代码]

Element-wise sign.

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

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

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

Element-wise sign:

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