mindspore.Tensor.new_ones
- Tensor.new_ones(size, dtype=None) Tensor[source]
- Return a tensor of size filled with ones. - Parameters
- Returns
- Tensor, the shape and dtype is defined above and filled with ones. 
- Raises
- TypeError – If size is neither an int nor a tuple/list of int. 
- TypeError – If dtype is not a MindSpore dtype. 
- ValueError – If size contains negative values. 
 
 - Supported Platforms:
- Ascend- GPU- CPU
 - Examples - >>> import mindspore >>> from mindspore import Tensor >>> x = Tensor((), mindspore.int32) >>> x.new_ones((2, 3)) Tensor(shape=[2, 3], dtype=Int32, value= [[1, 1, 1], [1, 1, 1]])