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

full_like This function creates a tensor filled with fill_value which has identical shape and dtype with input.

  • input (Variable) – The input tensor which specifies shape and data type. The data type can be bool, float16, float32, float64, int32, int64.

  • fill_value (bool|float|int) – The value to fill the tensor with. Default value is 0. Note: this value shouldn’t exceed the range of the output data type.

  • 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. Default value is None.

  • dtype (np.dtype|core.VarDesc.VarType|str, optional) – The data type of output. The default value is None, which means the output data type is the same as input.

  • device (string, optional) – Which device to run the operator. The device must be None, ‘cpu’, ‘gpu’. If device is None, it will be the device that the user set in the paddle program. 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


The Tensor variable storing the output.

Return type



import paddle
import paddle.fluid as fluid
import numpy as np
input = fluid.data(name='input', dtype='float32', shape=[2, 3])
output = fluid.layers.full_like(input, 2.0)
exe = fluid.Executor(fluid.CPUPlace())
img=np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
res = exe.run(fluid.default_main_program(), feed={'input':img}, fetch_list=[output])
print(res) # [array([[2., 2., 2.], [2., 2., 2.]], dtype=float32)]