megengine.functional.ones¶
- ones(shape, *, dtype='float32', device=None)[源代码]¶
 返回一个新创建的拥有指定shape且被1填充的tensor。
- 参数
 shape (int...) – 输出tensor的shape。
- 关键字参数
 dtype (
Tensor.dtype, optional) – output tensor data type.device (
Tensor.device, optional) – device on which to place the created tensor.
- 返回类型
 - 返回
 一个全1的tensor。
实际案例
>>> 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)