mindspore.ops.ones_like

mindspore.ops.ones_like(input, *, dtype=None)[source]

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

Parameters

input (Tensor) – Tensor of any dimension.

Keyword Arguments

dtype (mindspore.dtype, optional) – The specified dtype of the output tensor. If dtype is None, the dtype of the input tensor will be used. Default: None.

Returns

Tensor, has the same shape as input but filled with ones.

Raises

TypeError – If input is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

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