PyTorch torch.zeros_like Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.zeros_likeis a function in PyTorch used to create 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 Example

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 参考手册Pytorch torch Reference Manual

Other Extensions