full

paddle. full ( shape, fill_value, dtype=None, name=None ) [source]

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

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.

  • fill_value (bool|float|int|Tensor) – The constant value used to initialize the Tensor to be created. If fill_value is an Tensor, it shoule 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, if dytpe is None, the data type of created Tensor is float32.

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

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.]]