评价此页

torch.sign#

torch.sign(input, *, out=None) Tensor#

返回一个新张量,其中包含input元素的符号。

outi=sgn(inputi)\text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
参数

input (Tensor) – 输入张量。

关键字参数

out (Tensor, optional) – 输出张量。

示例

>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> a
tensor([ 0.7000, -1.2000,  0.0000,  2.3000])
>>> torch.sign(a)
tensor([ 1., -1.,  0.,  1.])