mindspore.mint.ones_like
- mindspore.mint.ones_like(input, *, dtype=None)[source]
Creates a tensor filled with 1, with the same shape as input, and its data type is determined by the given dtype.
If dtype = None, the tensor will have the same dtype as input input.
- Parameters
input (Tensor) – Tensor of any dimension.
- Keyword Arguments
dtype (
mindspore.dtype
, optional) – The specified dtype of the output tensor. If dtype isNone
, 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
Examples
>>> import numpy as np >>> from mindspore import Tensor, mint >>> x = Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)) >>> output = mint.ones_like(x) >>> print(output) [[1 1] [1 1]]