*Memos:
- My post explains Step function, Identity and ReLU.
- My post explains ReLU() and LeakyReLU().
- My post explains PReLU() and ELU().
- My post explains SELU() and CELU().
- My post explains GELU() and Mish().
- My post explains SiLU() and Softplus().
- My post explains Tanh() and Softsign().
- My post explains Sigmoid() and Softmax().
heaviside() can get the 0D or more D tensor of the zero or more values computed by Heaviside step function from the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
heaviside()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
orbool
). - The 2nd argument with
torch
or the 1st argument with a tensor isvalues
(Required-Type:tensor
ofint
,float
orbool
).
import torch
from torch import nn
my_tensor = torch.tensor([8, -3, 0, 1, 5, -2, -1, 4])
torch.heaviside(input=my_tensor,
values=torch.tensor(0))
my_tensor.heaviside(values=torch.tensor(0))
# tensor([1, 0, 0, 1, 1, 0, 0, 1])
torch.heaviside(input=my_tensor,
values=torch.tensor([0, 1, 2, 3, 4, 5, 6, 7]))
# tensor([1, 0, 2, 1, 1, 0, 0, 1])
my_tensor = torch.tensor([[8, -3, 0, 1],
[5, 0, -1, 4]])
torch.heaviside(input=my_tensor, values=torch.tensor(0))
# tensor([[1, 0, 0, 1],
# [1, 0, 0, 1]])
torch.heaviside(input=my_tensor,
values=torch.tensor([[0, 1, 2, 3],
[4, 5, 6, 7]]))
# tensor([[1, 0, 2, 1],
# [1, 5, 0, 1]])
my_tensor = torch.tensor([[[8, -3], [0, 1]],
[[5, 0], [-1, 4]]])
torch.heaviside(input=my_tensor, values=torch.tensor(0))
# tensor([[[1, 0], [0, 1]],
# [[1, 0], [0, 1]]])
torch.heaviside(input=my_tensor,
values=torch.tensor([[[0, 1], [2, 3]],
[[4, 5], [6, 7]]]))
# tensor([[[1, 0], [2, 1]],
# [[1, 5], [0, 1]]])
my_tensor = torch.tensor([[[8., -3.], [0., 1.]],
[[5., 0.], [-1., 4.]]])
torch.heaviside(input=my_tensor,
values=torch.tensor([[[0., 1.], [2., 3.]],
[[4., 5.], [6., 7.]]]))
# tensor([[[1., 0.], [2., 1.]],
# [[1., 5.], [0., 1.]]])
my_tensor = torch.tensor([[[True, False], [True, False]],
[[False, True], [False, True]]])
torch.heaviside(input=my_tensor,
values=torch.tensor([[[True, False], [True, False]],
[[False, True], [False, True]]]))
# tensor([[[True, False], [True, False]],
# [[False, True], [False, True]]])
Identity() can just get the same tensor as the input tensor which is the 0D or more D tensor of zero or more elements as shown below:
*Memos:
- For initialization, you can set 0 or more arguments but there is no influence.
- The 1st argument is
input
(Required-Type:tensor
ofint
orfloat
).
import torch
from torch import nn
my_tensor = torch.tensor([8, -3, 0, 1, 5, -2, -1, 4])
identity = nn.Identity()
identity(input=my_tensor)
# tensor([8, -3, 0, 1, 5, -2, -1, 4])
identity
# Identity()
identity = nn.Identity(num1=3, num2=5)
identity(input=my_tensor)
# tensor([8, -3, 0, 1, 5, -2, -1, 4])
my_tensor = torch.tensor([[8, -3, 0, 1],
[5, -2, -1, 4]])
identity = nn.Identity()
identity(input=my_tensor)
# tensor([[8, -3, 0, 1],
# [5, -2, -1, 4]])
my_tensor = torch.tensor([[[8, -3], [0, 1]],
[[5, -2], [-1, 4]]])
identity = nn.Identity()
identity(input=my_tensor)
# tensor([[[8, -3], [0, 1]],
# [[5, -2], [-1, 4]]])
my_tensor = torch.tensor([[[8., -3.], [0., 1.]],
[[5., -2.], [-1., 4.]]])
identity = nn.Identity()
identity(input=my_tensor)
# tensor([[[8., -3.], [0., 1.]],
# [[5., -2.], [-1., 4.]]])
Top comments (0)