megengine.functional.ones_like

ones_like(inp)[source]

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

Parameters

inp (Tensor) – input tensor from which to derive the output tensor shape.

Return type

Tensor

Returns

a tensor having the same shape as input tensor and filled with ones.

Examples

>>> 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)