megengine.functional.ones¶
- ones(shape, dtype='float32', device=None)[源代码]¶
返回一个具有给定形状的全1张量。
- 参数
shape – a list, tuple or integer defining the shape of the output tensor.
dtype – the desired data type of the output tensor. Default:
float32
.device – the desired device of the output tensor. Default: if
None
, use the default device (seeget_default_device
).
- 返回类型
- 返回
output tensor.
实际案例
import megengine.functional as F out = F.ones((2, 1)) print(out.numpy())
输出:
[[1.] [1.]]