TUTORIALAI 与数据科学FETCHED
PyTorch torch.clone 函数
PyTorch torch.clone 函数 Pytorch torch 参考手册 torch.clone 是 PyTorch 中用于返回张量副本的函数。 函数定义 torch.clone(input, memory_format) 使用示例 实例 [mycode4 type='python'] import torch x = torch.tensor([1, 2, 3]) # 创建副本 y..
更新于 2026/7/16
教程详情页默认 noindex。
PyTorch torch.clone 函数
torch.clone 是 PyTorch 中用于返回张量副本的函数。
函数定义
torch.clone(input, memory_format)
使用示例
实例
import torch
x = torch.tensor([1, 2, 3])
# 创建副本
y = torch.clone(x)
# 修改副本不影响原张量
y[0] = 100
print("原张量:", x)
print("副本:", y)
x = torch.tensor([1, 2, 3])
# 创建副本
y = torch.clone(x)
# 修改副本不影响原张量
y[0] = 100
print("原张量:", x)
print("副本:", y)
Pytorch torch 参考手册