mindspore.Tensor.new_ones
- Tensor.new_ones(size, dtype=None)[source]
Return a tensor of size filled with ones.
Warning
For argument size, Tensor type input will be deprecated in the future version.
- Parameters
size (Union[int, tuple, list, Tensor]) – An int, list or tuple of integers defining the output shape.
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 neither an int nor an tuple/list/Tensor of int.
- 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.]]