full_like

paddle. full_like ( x, fill_value, dtype=None, name=None ) [source]

This function creates a tensor filled with fill_value which has identical shape of x and dtype. If the dtype is None, the data type of Tensor is same with x.

Parameters
  • x (Tensor) – 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. Note: this value shouldn’t exceed the range of the output data type.

  • dtype (np.dtype|str, optional) – The data type of output. The data type can be one of bool, float16, float32, float64, int32, int64. The default value is None, which means the output data type is the same as input.

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

Return type

Tensor

Examples

import paddle
import numpy as np

input = paddle.full(shape=[2, 3], fill_value=0.0, dtype='float32', name='input')
output = paddle.full_like(input, 2.0)
# [[2. 2. 2.]
#  [2. 2. 2.]]