From 7138e4fd02ef4844ff0dc3d60c8c2ab27b314b6c Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 23 Jul 2021 18:51:53 +0800 Subject: [PATCH] feat(docs): add docs for megengine.functional.full GitOrigin-RevId: 8428a0c9a90b92570dc0f35f03d7cf79ec284c2a --- .../python/megengine/functional/tensor.py | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/imperative/python/megengine/functional/tensor.py b/imperative/python/megengine/functional/tensor.py index 1ecb71f74..b9fc118f4 100755 --- a/imperative/python/megengine/functional/tensor.py +++ b/imperative/python/megengine/functional/tensor.py @@ -96,9 +96,34 @@ def eye(N, M=None, *, dtype="float32", device: Optional[CompNode] = None) -> Ten def full(shape, value, dtype="float32", device=None) -> Tensor: + r""" + Creates a tensor of shape ``shape`` filled with ``value``. + + :param shape: a list, tuple or integer defining the shape of the output tensor. + :param value: the value to fill the output tensor with. + :param dtype: the desired data type of the output tensor. Default: ``float32``. + :param device: the desired device of the output tensor. Default: if ``None``, use the default device(see ``megengine.get_default_device()``). + :return: output tensor. + + Examples: + + .. testcode:: + + import numpy as np + import megengine.functional as F + + out = F.full([2,3], 1.5) + print(out.numpy()) + + Outputs: + + .. testoutput:: + + [[1.5 1.5 1.5] + [1.5 1.5 1.5]] + """ - Returns a tensor with given shape and value. - """ + if isinstance(shape, int): shape = (shape,) if device is None: -- GitLab