Browse Source

Merge pull request #421 from Asthestarsfalll:master

GitOrigin-RevId: 416b327415
tags/v1.8.0
Megvii Engine Team 3 years ago
parent
commit
714340e912
1 changed files with 7 additions and 20 deletions
  1. +7
    -20
      imperative/python/megengine/functional/tensor.py

+ 7
- 20
imperative/python/megengine/functional/tensor.py View File

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



Loading…
Cancel
Save