mindspore.ops.OnesLike

class mindspore.ops.OnesLike[source]

Returns a Tensor with a value of 1 and its shape and data type is the same as the input.

Inputs:
  • input_x (Tensor) - Tensor of any dimension.

Outputs:

Tensor, has the same shape and type as input_x but filled with ones.

Raises

TypeError – If input_x is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> oneslike = ops.OnesLike()
>>> input_x = Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32))
>>> output = oneslike(input_x)
>>> print(output)
[[1 1]
 [1 1]]