PyTorch torch.randn_like function
PyTorch torch reference manual
torch.randn_like is a function in PyTorch used to create a standard normal distributed random tensor with the same shape as the input tensor.
Function definition
torch.randn_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 a standard normal distributed random tensor with the same shape as the input
x
=
torch.
randn_like
(
input
)
(
x
)