mindspore.ops.ones_like

mindspore.ops.ones_like(input_x)[source]

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

Parameters

input_x (Tensor) – Tensor of any dimension.

Returns

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

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