mindspore.ops.Ones
- class mindspore.ops.Ones[source]
Creates a tensor filled with value ones.
Refer to
mindspore.ops.ones()
for more details.Warning
For argument size, Tensor type input will be deprecated in the future version.
- Inputs:
shape (Union[tuple[int], List[int], int, Tensor]) - The specified shape of output tensor.
type (
mindspore.dtype
) - The specified type of output tensor.
- Outputs:
Tensor, whose dtype and size are defined by input.
- Raises
TypeError – If shape is neither an int nor a tuple/list/Tensor of int.
- 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.]]