mindspore.ops.Ones
- class mindspore.ops.Ones(*args, **kwargs)[source]
Creates a tensor filled with value ones.
Creates a tensor with shape described by the first argument and fills it with value ones in type of the second argument.
- Inputs:
shape (Union[tuple[int], int]) - The specified shape of output tensor. Only constant positive int is allowed.
type (mindspore.dtype) - The specified type of output tensor. Only constant value is allowed.
- Outputs:
Tensor, has the same type and shape as input shape value.
- Raises
TypeError – If shape is neither tuple nor int.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> from mindspore.ops import operations as ops >>> ones = ops.Ones() >>> output = ones((2, 2), mindspore.float32) >>> print(output) [[1. 1.] [1. 1.]]