PyTorch torch.clone function
PyTorch torch reference manual
torch.clone is a function in PyTorch used to return a copy of a tensor.
Function definition
torch.clone(input, memory_format)
Usage examples
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
(
"Original tensor:"
,
x
)
(
"Copy:"
,
y
)