mean¶
- paddle. mean ( x, axis=None, keepdim=False, name=None ) [source]
-
Computes the mean of the input tensor’s elements along
axis.- Parameters
-
x (Tensor) – The input Tensor with data type float32, float64.
axis (int|list|tuple, optional) – The axis along which to perform mean calculations.
axisshould be int, list(int) or tuple(int). Ifaxisis a list/tuple of dimension(s), mean is calculated along all element(s) ofaxis.axisor element(s) ofaxisshould be in range [-D, D), where D is the dimensions ofx. Ifaxisor element(s) ofaxisis less than 0, it works the same way as \(axis + D\) . Ifaxisis None, mean is calculated over all elements ofx. Default is None.keepdim (bool, optional) – Whether to reserve the reduced dimension(s) in the output Tensor. If
keepdimis True, the dimensions of the output Tensor is the same asxexcept in the reduced dimensions(it is of size 1 in this case). Otherwise, the shape of the output Tensor is squeezed inaxis. Default is False.name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Tensor, results of average along
axisofx, with the same data type asx.
Examples
import paddle x = paddle.to_tensor([[[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.]], [[13., 14., 15., 16.], [17., 18., 19., 20.], [21., 22., 23., 24.]]]) out1 = paddle.mean(x) # [12.5] out2 = paddle.mean(x, axis=-1) # [[ 2.5 6.5 10.5] # [14.5 18.5 22.5]] out3 = paddle.mean(x, axis=-1, keepdim=True) # [[[ 2.5] # [ 6.5] # [10.5]] # [[14.5] # [18.5] # [22.5]]] out4 = paddle.mean(x, axis=[0, 2]) # [ 8.5 12.5 16.5]
