megengine.functional.ones_like

ones_like(inp)[源代码]

返回一个与输入张量形状相同的全1张量

参数

inp (Union[Tensor, SymbolVar]) – input tensor.

返回类型

Union[Tensor, SymbolVar]

返回

output ones tensor.

Examples:

import numpy as np
from megengine import tensor
import megengine.functional as F

inp = tensor(np.arange(1, 7, dtype=np.int32).reshape(2,3))
out = F.ones_like(inp)
print(out.numpy())

Outputs:

[[1 1 1]
 [1 1 1]]