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

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

Returns a Tensor of size size filled with uninitialized data. 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.ones(()) tensor.new_empty((2, 3)) tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30], [ 3.0949e-41, 4.4842e-44, 0.0000e+00]])