PyTorch torch.sgn 函数

约 220 字 更新于 2026-11-18 5iyo.com

PyTorch torch.sgn 函数


torch.sgn 是 PyTorch 中用于逐元素返回符号向量的函数。对于复数返回单位复数。

函数定义

torch.sgn(input, out=None)

使用示例

实例

import torch

# 逐元素返回符号向量
x = torch.tensor([-2.0, 0.0, 3.0])
result = torch.sgn(x)
print(result)