full

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

This Op return a Tensor with the fill_value which size is same as shape.

Parameters
  • shape (list|tuple|Tensor) – Shape of the Tensor to be created. The data type is int32 or int64 . If shape is a list or tuple, the elements of it should be integers or Tensors with shape [1]. If shape is an Tensor, it should be an 1-D Tensor .

  • fill_value (bool|float|int|Tensor) – The constant value used to initialize the Tensor to be created. If fill_value is an Tensor, it must be an 1-D Tensor.

  • 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) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

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

Return type

Tensor

Examples

import paddle

data1 = paddle.full(shape=[2,1], fill_value=0, dtype='int64')
#[[0]
# [0]]

# attr shape is a list which contains Tensor.
positive_2 = paddle.full([1], 2, "int32")
data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5)
# [[1.5 1.5]]

# attr shape is a Tensor.
shape = paddle.full([2], 2, "int32")
data4 = paddle.full(shape=shape, dtype='bool', fill_value=True)
# [[True True]
#  [True True]]

# attr fill_value is a Tensor.
val = paddle.full([1], 2.0, "float32")
data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32')
# [[2.0]
#  [2.0]]