new_full

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

Create a new Tensor of specified shape and fill it with a given value.

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

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

  • fill_value (bool | float | Tensor) – Value to fill the Tensor with.

  • 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 Tensor filled with fill_value.

Return type

Tensor

Examples

>>> import paddle
>>> x = paddle.ones([2, 2])
>>> y = x.new_full([3, 3], 5.0)
>>> y.numpy()
array([[5., 5., 5.],
       [5., 5., 5.],
       [5., 5., 5.]], dtype=float32)