mindspore.Tensor.new_ones
- Tensor.new_ones(size, *, dtype=None)[source]
Return a tensor of size filled with ones.
- Parameters
size (Union[int, tuple, list]) – An int, list or tuple of integers defining the output shape.
- Keyword Arguments
dtype (mindspore.dtype, optional) – The desired dtype of the output tensor. If None, the returned tensor has the same dtype as self. Default:
None
.- Returns
Tensor, the shape and dtype is defined above and filled with ones.
- Raises
TypeError – If size is not an int, list or tuple of integers.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> import mindspore >>> from mindspore import Tensor >>> x = Tensor(np.array([1, 2, 3]), mindspore.float32) >>> output = x.new_ones((2, 2)) >>> print(output) [[1. 1.] [1. 1.]]