PyTorch torch.copysign 函数
torch.copysign 是 PyTorch 中用于逐元素复制符号的函数。
函数定义
torch.copysign(input, other, *, out=None)
使用示例
实例
import torch
# 复制符号示例
x = torch.tensor([1.0, -2.0, 3.0, -4.0])
y = torch.tensor([-1.0, -1.0, 1.0, 1.0])
result = torch.copysign(x, y)
print(result) # tensor([-1., -2., 3., -4.])
# 复制符号示例
x = torch.tensor([1.0, -2.0, 3.0, -4.0])
y = torch.tensor([-1.0, -1.0, 1.0, 1.0])
result = torch.copysign(x, y)
print(result) # tensor([-1., -2., 3., -4.])

Pytorch torch 参考手册