mindspore.ops.full_like

View Source On Gitee
mindspore.ops.full_like(input, fill_value, *, dtype=None)[source]

Return a Tensor of the same shape as input and filled with fill_value.

Parameters
  • input (Tensor) – input Tensor and the output Tensor have the same shape as input.

  • fill_value (Number) – Value to fill the returned Tensor. Complex numbers are not supported for now.

Keyword Arguments

dtype (mindspore.dtype, optional) – The specified type of output tensor. bool_ and number are supported, for details, please refer to mindspore.dtype . Default: None .

Returns

Tensor.

Raises

TypeError – If input is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> input = Tensor([[0, 1], [2, 1]], dtype=mindspore.int32)
>>> output = ops.full_like(input, 1)
>>> print(output)
[[1. 1.]
 [1. 1.]]
>>> input = Tensor([[0, 1, 1], [2, 1, 2], [1, 3, 4]], dtype=mindspore.int32)
>>> output = ops.full_like(input, 0)
>>> print(output)
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]