diff --git a/imperative/python/megengine/functional/tensor.py b/imperative/python/megengine/functional/tensor.py index e8ff2e6a2da9addf02860e967aeaa3daae2c5dc5..67693ace946a84886d87a7c26ffceddec501f280 100755 --- a/imperative/python/megengine/functional/tensor.py +++ b/imperative/python/megengine/functional/tensor.py @@ -240,32 +240,19 @@ def zeros_like(inp: Union[Tensor, SymbolVar]) -> Union[Tensor, SymbolVar]: def ones_like(inp: Union[Tensor, SymbolVar]) -> Union[Tensor, SymbolVar]: - r"""Returns a ones tensor with the same shape as input tensor. + r"""Returns a tensor filled with ones with the same shape and data type as input tensor. Args: - inp: input tensor. + inp (Tensor): input tensor. Return: - output tensor. + a tensor containing ones. Examples: - - .. testcode:: - - 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: - - .. testoutput:: - - [[1 1 1] - [1 1 1]] + >>> 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) """ return full_like(inp, 1.0)