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

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

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

Parameters

fill_value (scalar) – the number to fill the output tensor with.

Keyword Arguments

Example:

tensor = torch.ones((2,), dtype=torch.float64) tensor.new_full((3, 4), 3.141592) tensor([[ 3.1416, 3.1416, 3.1416, 3.1416], [ 3.1416, 3.1416, 3.1416, 3.1416], [ 3.1416, 3.1416, 3.1416, 3.1416]], dtype=torch.float64)