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