PyTorch torch.full_like function
PyTorch torch reference manual
torch.full_like A function in PyTorch for creating a filled tensor with the same shape as the input tensor.
Function definition
torch.full_like(input, fill_value, 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 all-7 tensor with the same shape as the input
x
=
torch.
full_like
(
input
,
7
)
(
x
)