MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / ones_like

Function ones_like

imperative/python/megengine/functional/tensor.py:410–425  ·  view source on GitHub ↗

r"""Returns a tensor filled with ones with the same shape and data type as input tensor. Args: inp(Tensor): input tensor from which to derive the output tensor shape. Return: a tensor having the same shape as input tensor and filled with ones. Examples: >>> x =

(inp: Tensor)

Source from the content-addressed store, hash-verified

408
409
410def ones_like(inp: Tensor) -> Tensor:
411 r"""Returns a tensor filled with ones with the same shape and data type as input tensor.
412
413 Args:
414 inp(Tensor): input tensor from which to derive the output tensor shape.
415
416 Return:
417 a tensor having the same shape as input tensor and filled with ones.
418
419 Examples:
420 >>> x = F.arange(6, dtype='int32').reshape(2, 3)
421 >>> F.ones_like(x)
422 Tensor([[1 1 1]
423 [1 1 1]], dtype=int32, device=xpux:0)
424 """
425 return full_like(inp, 1.0)
426
427
428def polar(abs: Tensor, angle: Tensor) -> Tensor:

Callers 1

tileFunction · 0.70

Calls 1

full_likeFunction · 0.85

Tested by

no test coverage detected