PyTorch torch.heaviside function
Pytorch torch Reference Manual
torch.heavisideIt is a function in PyTorch used to compute the Heaviside step function. It returns 1 when the input value is greater than 0, 0.5 when equal to 0, and 0 when less than 0.
Function Definition
torch.heaviside(input, values)
Usage Example
Example
import torch
# Create input tensor
input = torch.tensor([-1.0, -0.5, 0.0, 0.5, 1.0])
# Specify the return value when input is 0
values = torch.tensor([0.5])
# Compute the Heaviside step function
x = torch.heaviside(input, values)
print(x)
# Create input tensor
input = torch.tensor([-1.0, -0.5, 0.0, 0.5, 1.0])
# Specify the return value when input is 0
values = torch.tensor([0.5])
# Compute the Heaviside step function
x = torch.heaviside(input, values)
print(x)
Other Extensions