megengine.functional.ones#
- ones(shape, *, dtype='float32', device=None)[source]#
Returns a new tensor having a specified shape and filled with ones.
- Parameters:
shape (int...) – the shape of the output tensor.
- Keyword Arguments:
dtype (
Tensor.dtype
, optional) – output tensor data type.device (
Tensor.device
, optional) – device on which to place the created tensor.
- Return type:
- Returns:
a tensor containing ones.
Examples
>>> F.ones(5) Tensor([1. 1. 1. 1. 1.], device=xpux:0) >>> F.ones((5, ), dtype='int32') Tensor([1 1 1 1 1], dtype=int32, device=xpux:0) >>> F.ones((2, 2)) Tensor([[1. 1.] [1. 1.]], device=xpux:0)