megengine.functional.ones_like¶
- ones_like(inp)[源代码]¶
使用输入 Tensor 来填充输出 Tensor,保持相同的形状和数据类型。
- 参数
inp (Tensor) – input tensor from which to derive the output tensor shape.
- 返回类型
- 返回
a tensor having the same shape as input tensor and filled with ones.
实际案例
>>> x = F.arange(6, dtype='int32').reshape(2, 3) >>> F.ones_like(x) Tensor([[1 1 1] [1 1 1]], dtype=int32, device=xpux:0)