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

PyTorch torch.empty_like function

PyTorch torch.empty_like function


PyTorch torch reference manual PyTorch torch reference manual

torch.empty_like is a PyTorch function for creating an uninitialized tensor with the same shape as the input tensor.

Function definition

torch.empty_like(input, dtype=None, device=None, requires_grad=False)


Usage examples

Example

import

torch

Create an input tensor

input

=

torch.

tensor

(

[

[

1

,

2

]

,

[

3

,

4

]

]

)

Create an uninitialized tensor with the same shape as the input

x

=

torch.

empty_like

(

input

)

print

(

x

)

print

(

"Note: values are uninitialized memory values"

)


PyTorch torch reference manual PyTorch torch reference manual