PyTorch torch.heaviside function
PyTorch torch reference manual
torch.heaviside A function in PyTorch for computing the Heaviside step function. Returns 1 when the input value is greater than 0, 0.5 when it equals 0, and 0 when it is less than 0.
Function definition
torch.heaviside(input, values)
Usage examples
Example
import
torch
Create an input tensor
input
=
torch.
tensor
(
[
1.0
,
0.5
,
0.0
,
0.5
,
1.0
]
)
Specify the return value when the input is 0
values
=
torch.
tensor
(
[
0.5
]
)
Compute the Heaviside step function
x
=
torch.
heaviside
(
input
,
values
)
(
x
)