PyTorch torch.empty_like function
PyTorch torch reference manual
torch.empty_like is a PyTorch function for creating an uninitialized tensor with the same shape as the input tensor.
Function definition
torch.empty_like(input, dtype=None, device=None, requires_grad=False)
Usage examples
Example
import
torch
Create an input tensor
input
=
torch.
tensor
(
[
[
1
,
2
]
,
[
3
,
4
]
]
)
Create an uninitialized tensor with the same shape as the input
x
=
torch.
empty_like
(
input
)
(
x
)
(
"Note: values are uninitialized memory values"
)