megengine.functional.ones_like

ones_like(inp)[源代码]

Returns a tensor filled with ones with the same shape and data type as input tensor.

参数

inp (Tensor) – 输入张量。

返回类型

Union[Tensor, SymbolVar]

返回

一个全1的tensor。

实际案例

>>> input = F.arange(6, dtype='int32').reshape(2,3)
>>> F.ones_like(input)
Tensor([[1 1 1]
 [1 1 1]], dtype=int32, device=xpux:0)