評價此頁

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.])