torch.sign¶ torch.sign(input, *, out=None) → Tensor¶ 返回一個新張量,其元素是 input 中元素的符號。 outi=sgn(inputi)\text{out}_{i} = \operatorname{sgn}(\text{input}_{i}) outi=sgn(inputi) 引數 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.])