Computes the mean of the input tensor's elements along ``axis``. Args: x (Tensor): The input Tensor with data type bool, bfloat16, float16, float32, float64, int32, int64, complex64, complex128. alias: ``input`` axis (int|list|tuple|None, optional):
(
x: Tensor,
axis: int | Sequence[int] | None = None,
keepdim: bool = False,
name: str | None = None,
*,
dtype: DTypeLike | None = None,
out: Tensor | None = None,
)
| 51 | |
| 52 | @param_two_alias(["x", "input"], ["axis", "dim"]) |
| 53 | def mean( |
| 54 | x: Tensor, |
| 55 | axis: int | Sequence[int] | None = None, |
| 56 | keepdim: bool = False, |
| 57 | name: str | None = None, |
| 58 | *, |
| 59 | dtype: DTypeLike | None = None, |
| 60 | out: Tensor | None = None, |
| 61 | ) -> Tensor: |
| 62 | """ |
| 63 | Computes the mean of the input tensor's elements along ``axis``. |
| 64 | |
| 65 | Args: |
| 66 | x (Tensor): The input Tensor with data type bool, bfloat16, float16, float32, |
| 67 | float64, int32, int64, complex64, complex128. |
| 68 | alias: ``input`` |
| 69 | axis (int|list|tuple|None, optional): The axis along which to perform mean |
| 70 | calculations. ``axis`` should be int, list(int) or tuple(int). If |
| 71 | ``axis`` is a list/tuple of dimension(s), mean is calculated along |
| 72 | all element(s) of ``axis`` . ``axis`` or element(s) of ``axis`` |
| 73 | should be in range [-D, D), where D is the dimensions of ``x`` . If |
| 74 | ``axis`` or element(s) of ``axis`` is less than 0, it works the |
| 75 | same way as :math:`axis + D` . If ``axis`` is None, mean is |
| 76 | calculated over all elements of ``x``. Default is None. |
| 77 | alias: ``dim`` |
| 78 | keepdim (bool, optional): Whether to reserve the reduced dimension(s) |
| 79 | in the output Tensor. If ``keepdim`` is True, the dimensions of |
| 80 | the output Tensor is the same as ``x`` except in the reduced |
| 81 | dimensions(it is of size 1 in this case). Otherwise, the shape of |
| 82 | the output Tensor is squeezed in ``axis`` . Default is False. |
| 83 | name (str|None, optional): Name for the operation (optional, default is None). |
| 84 | For more information, please refer to :ref:`api_guide_Name`. |
| 85 | dtype (str): The desired data type of returned tensor. Default: None. |
| 86 | out(Tensor|None, optional): The output tensor. Default: None. |
| 87 | |
| 88 | Returns: |
| 89 | Tensor, results of average along ``axis`` of ``x``, with the same data |
| 90 | type as ``x``. |
| 91 | |
| 92 | Examples: |
| 93 | .. code-block:: pycon |
| 94 | |
| 95 | >>> import paddle |
| 96 | |
| 97 | >>> x = paddle.to_tensor( |
| 98 | ... [ |
| 99 | ... [ |
| 100 | ... [1.0, 2.0, 3.0, 4.0], |
| 101 | ... [5.0, 6.0, 7.0, 8.0], |
| 102 | ... [9.0, 10.0, 11.0, 12.0], |
| 103 | ... ], |
| 104 | ... [ |
| 105 | ... [13.0, 14.0, 15.0, 16.0], |
| 106 | ... [17.0, 18.0, 19.0, 20.0], |
| 107 | ... [21.0, 22.0, 23.0, 24.0], |
| 108 | ... ], |
| 109 | ... ] |
| 110 | ... ) |