PyTorch torch.full_like Function
Pytorch torch Reference Manual
torch.full_likeis a function in PyTorch used to create 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 Example
Example
import torch
# Create an input tensor
input = torch.tensor([[1, 2], [3, 4]])
# Create a tensor of all 7s with the same shape as the input
x = torch.full_like(input, 7)
print(x)
# Create an input tensor
input = torch.tensor([[1, 2], [3, 4]])
# Create a tensor of all 7s with the same shape as the input
x = torch.full_like(input, 7)
print(x)
Other Extensions