PyTorch torch.clone Function


Pytorch torch 参考手册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)

Pytorch torch 参考手册PyTorch torch Reference Manual

Other Extensions