mindspore.ops.Ones

class mindspore.ops.Ones[source]

Creates a tensor filled with value ones.

Refer to mindspore.ops.ones() for more details.

Inputs:
  • shape (Union[tuple[int], int]) - The specified shape of output tensor.

  • type (mindspore.dtype) - The specified type of output tensor.

Outputs:

Tensor, has the same type and shape as input shape value.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import ops
>>> ones = ops.Ones()
>>> output = ones((2, 2), mindspore.float32)
>>> print(output)
[[1. 1.]
 [1. 1.]]
>>> output = ones((3, 3), mindspore.float32)
>>> print(output)
[[1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]]