mindspore.ops.ones
- mindspore.ops.ones(shape, type)[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.
- Parameters
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.
- Returns
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
>>> output = ops.ones((2, 2), mindspore.float32) >>> print(output) [[1. 1.] [1. 1.]] >>> output = ops.ones((3, 3), mindspore.float32) >>> print(output) [[1. 1. 1.] [1. 1. 1.] [1. 1. 1.]]