PyTorch torch.copysign Function
PyTorch torch Reference Manual
torch.copysignis a function in PyTorch used to copy the sign element-wise.
Function Definition
torch.copysign(input, other, *, out=None)
Usage Example
Example
import torch
# Copy sign example
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.])
# Copy sign example
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.])
Other Extensions