full

paddle. full ( shape: ShapeLike, fill_value: Numeric | str, dtype: DTypeLike | None = None, name: str | None = None, *, out: paddle.Tensor | None = None, device: PlaceLike | None = None, requires_grad: bool = False, pin_memory: bool = False ) paddle.Tensor [source]

Return a Tensor with the fill_value which size is same as shape.

Note

Alias Support: The parameter name size can be used as an alias for shape. For example, full(size=[2, 3], …) is equivalent to full(shape=[2, 3], …).

Parameters
  • shape (tuple|list|Tensor) – Shape of the Tensor to be created. The data type is int32 or int64 . If shape is a list or tuple, each element of it should be integer or 0-D Tensor with shape []. If shape is an Tensor, it should be an 1-D Tensor which represents a list. Alias: size.

  • fill_value (Scalar|Tensor) – The constant value used to initialize the Tensor to be created. If fill_value is an Tensor, it should be an 0-D Tensor which represents a scalar.

  • dtype (np.dtype|str, optional) – Data type of the output Tensor which can be float16, float32, float64, int32, int64, complex64, complex128. If dtype is None, the data type of created Tensor is float32.

  • name (str|None, optional) – For details, please refer to api_guide_Name. Generally, no setting is required. Default: None.

  • out (Tensor, optional) – The output tensor.

  • device (PlaceLike|None, optional) – The desired device of returned tensor. if None, uses the current device for the default tensor type (see paddle.device.set_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • pin_memory (bool, optional) – If set, return tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False

Returns

Tensor which is created according to shape, fill_value and dtype.

Return type

Tensor

Examples

>>> import paddle

>>> # shape is a list/tuple
>>> data1 = paddle.full(shape=[3, 2], fill_value=1.)
>>> print(data1.numpy())
[[1. 1.]
 [1. 1.]
 [1. 1.]]

>>> # shape is a Tensor
>>> shape = paddle.to_tensor([3, 2])
>>> data2 = paddle.full(shape=shape, fill_value=2.)
>>> print(data2.numpy())
[[2. 2.]
 [2. 2.]
 [2. 2.]]

>>> # shape is a Tensor List
>>> shape = [paddle.to_tensor(3), paddle.to_tensor(2)]
>>> data3 = paddle.full(shape=shape, fill_value=3.)
>>> print(data3.numpy())
[[3. 3.]
 [3. 3.]
 [3. 3.]]

>>> # fill_value is a Tensor.
>>> val = paddle.full([], 2.0, "float32")
>>> data5 = paddle.full(shape=[3, 2], fill_value=val)
>>> print(data5.numpy())
[[2. 2.]
 [2. 2.]
 [2. 2.]]