full_like

paddle. full_like ( x: paddle.Tensor, fill_value: Numeric | str, dtype: DTypeLike | None = None, name: str | None = None, *, device: PlaceLike | None = None, requires_grad: bool = False, pin_memory: bool = False ) paddle.Tensor [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.

Note

Alias Support: The parameter name input can be used as an alias for x. For example, full_like(input=tensor_x, ...) is equivalent to full_like(x=tensor_x, ...).

Parameters
  • x (Tensor) – The input tensor which specifies shape and data type. The data type can be bool, float16, float32, float64, int32, int64. alias: input.

  • fill_value (Scalar|Tensor) – The value to fill the tensor with. Note: this value shouldn’t exceed the range of the output data type. If fill_value is an Tensor, it should be an 0-D Tensor which represents a scalar.

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

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

  • device (PlaceLike|None, optional) – The desired device of returned tensor. if None, uses the current device for the default tensor type (see paddle.device.set_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • pin_memory (bool, optional) – If set, return tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False

Returns

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

Return type

Tensor

Examples

>>> import paddle

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