new_empty

paddle.Tensor. new_empty ( var: Tensor, size: ShapeLike, *, dtype: DTypeLike | None = None, device: PlaceLike | None = None, requires_grad: bool = False, pin_memory: bool = False ) Tensor

Create a new uninitialized Tensor of the specified shape.

Parameters
  • var (Tensor) – A reference Tensor for default dtype and device.

  • size (ShapeLike) – Shape of the new Tensor.

  • dtype (DTypeLike, optional) – Desired data type of the new Tensor. Defaults to var.dtype.

  • device (PlaceLike, optional) – Device on which to place the new Tensor. Defaults to var.place.

  • requires_grad (bool, optional) – Whether to track gradients. Default: False.

  • pin_memory (bool, optional) – Whether to pin memory. Default: False.

Returns

A new uninitialized Tensor with the specified shape.

Return type

Tensor

Examples

>>> import paddle
>>> x = paddle.ones([2, 2])
>>> y = x.new_empty(3, 3)  # type: ignore
>>> y.shape
paddle.Size([3, 3])