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

PyTorch torch.zeros_like function

PyTorch torch.zeros_like function


PyTorch torch reference manual PyTorch torch reference manual

torch.zeros_like A function in PyTorch for creating an all-zero tensor with the same shape as the input tensor.

Function definition

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


Usage examples

Example

import

torch

x

=

torch.

randn

(

3

,

4

)

y

=

torch.

zeros_like

(

x

)

print

(

"x shape:"

,

x.

shape

)

print

(

"y shape:"

,

y.

shape

)

print

(

y

)


PyTorch torch reference manual PyTorch torch reference manual