torch.Tensor.new_zeros — PyTorch 2.7 documentation (original) (raw)

Tensor.new_zeros(size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) → Tensor

Returns a Tensor of size size filled with 0. By default, the returned Tensor has the same torch.dtype andtorch.device as this tensor.

Parameters

size (int...) – a list, tuple, or torch.Size of integers defining the shape of the output tensor.

Keyword Arguments

Example:

tensor = torch.tensor((), dtype=torch.float64) tensor.new_zeros((2, 3)) tensor([[ 0., 0., 0.], [ 0., 0., 0.]], dtype=torch.float64)