Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.clone function

PyTorch torch.clone function


PyTorch torch reference manual 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

print

(

"Original tensor:"

,

x

)

print

(

"Copy:"

,

y

)


PyTorch torch reference manual PyTorch torch reference manual