full

paddle.fluid.layers.full(shape, fill_value, out=None, dtype=None, device=None, stop_gradient=True, name=None)[source]

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

Parameters
  • shape (list|tuple|Variable) – 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 Variable, it should be an 1-D Tensor .

  • fill_value (bool|float16|float32|float64|int32|int64|Variable) – The constant value used to initialize the Tensor to be created. If fill_value is an Variable, it must be an 1-D Tensor.

  • out (Variable, optional) – Optional output which can be any created Variable that meets the requirements to store the result of operation. if out is None, a new Varibale will be create to store the result.

  • dtype (np.dtype|core.VarDesc.VarType|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

  • device (str, optional) – On which device to run this Op. The device must be None, ‘cpu’ or ‘gpu’. If device is None, the device that the user set in the paddle program will be chosen. Default value is None.

  • stop_gradient (bool, optional) – Indicating if we stop gradient from current(out) Variable, default value is True.

  • 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 and dtype.

Return type

Variable

Raises
  • TypeError – The dtype must be one of None, bool, float16, float32, float64, int32 and int64.

  • TypeError – The out must be a Variable.

  • TypeError – The shape must be one of Variable, list tuple.

Examples

import paddle.fluid as fluid

data1 = fluid.layers.full(shape=[2,1], fill_value=0, dtype='int64') # data1=[[0],[0]]
data2 = fluid.layers.full(shape=[2,1], fill_value=5, dtype='int64', device='gpu') # data2=[[5],[5]]

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

# attr shape is an Variable Tensor.
shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2]
data4 = fluid.layers.full(shape=shape, dtype='bool', fill_value=True) # data4=[[True,True],[True,True]]

# attr value is an Variable Tensor.
val = fluid.layers.fill_constant([1], "float32", 2.0) # val=[2.0]
data5 = fluid.layers.full(shape=[2,1], fill_value=val, dtype='float32') #data5=[[2.0],[2.0]]