PyTorch torch.empty_like Function
PyTorch torch Reference Manual
torch.empty_likeIt is a function in PyTorch used to create 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 Example
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)
print(x)
print("Note: The values are uninitialized memory values.")
# 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)
print(x)
print("Note: The values are uninitialized memory values.")
Other Extensions