PyTorch torch.clone Function
PyTorch torch Reference Manual
torch.cloneis a function in PyTorch used to return a copy of a tensor.
Function Definition
torch.clone(input, memory_format)
Usage Example
Example
import torch
x = torch.tensor([1, 2, 3])
# Create a copy
y = torch.clone(x)
# Modifying the copy does not affect the original tensor
y[0] = 100
print("Original tensor:", x)
print("Copy:", y)
x = torch.tensor([1, 2, 3])
# Create a copy
y = torch.clone(x)
# Modifying the copy does not affect the original tensor
y[0] = 100
print("Original tensor:", x)
print("Copy:", y)
Other Extensions