mean
The average value of the array elements.
| Library |
|
Syntax
Function call
-
M = mean(A)— returns the average value of the array elementsAaccording to the first dimension, the size of which is not equal to1.-
If
A— vector, thenmean(A)returns the average value of the elementsA. -
If
A— the matrix, thenmean(A)— vector is a row containing the average value of each columnA. -
If
A— a multidimensional array, thenmean(A)it operates on the first dimensionA, the size of which is not equal to1considering the elements as vectors. SizeMin this dimension , it becomes equal to1, while the dimensions of all other dimensions remain the same as inA.
-
-
M = mean(A, vecdim)— returns the average value for the dimension specified in the vectorvecdim. For example, ifA— the matrix, thenmean(A,[],[1 2])returns the average value for all elements of the matrixAsince each element of the matrix is contained in an array layer defined by the dimensions1and2.
-
M = mean(_, missingflag)— also specifies how to handle missing values for any of the previous syntax options. For example,mean(A,"omitnan")ignores all missing values when calculating the average. By defaultmeanincludes missing values.
-
M = mean(_, Weight=W)— defines the weighing schemeWand returns the weighted average. For more information, see Weighted average.
Arguments
Input arguments
# A — input data
+
scalar | vector | the matrix | multidimensional array
Details
Input data specified as a scalar, vector, matrix, or multidimensional array.
-
If
A— a scalar, thenmean(A)returnsA. -
If
A— an empty matrix of size0on0Thenmean(A)returnsNaN.
| Типы данных |
|
# dim — the measurement for which the operation is performed
+
scalar
Details
The dimension on which the operation is performed is set as a positive integer scalar. If no dimension is specified, then the first dimension of the array is used by default, the size of which is not equal to 1.
Dimension dim specifies a dimension whose length is reduced to 1. Size size(M, dim) equal to 1, while the dimensions of all other dimensions remain the same.
Consider the input matrix A size on :
# vecdim — measurement vector
+
vector
Details
A vector of dimensions defined as a vector of positive integers. Each element represents a dimension of the input array. The length of the output data in the specified operating measurements is 1, while the other dimensions remain unchanged.
Consider the input array A size 2×3×3. Then std(A,0,[1 2]) returns an array of size 1×1×3, the elements of which are the average values calculated for each layer A.
# missingflag — condition for missing a value
+
"includemissing" (by default) | "includenan" | "omitmissing" | "omitnan"
Details
The condition for missing a value, set as:
-
"includemissing"or"includenan"when calculating the average value, it takes into account the missing values in the input data.A. If any element is missing in the working dimension, then the corresponding element in theMalso missing. -
"omitmissing"or"omitnan"ignores missing values in the input data when calculating the average value.A. If all the elements in the working dimension are missing, then the corresponding element inMalso missing.
# W — weighing scheme
+
vector | the matrix | multidimensional array
Details
A weighting scheme defined as a vector, matrix, or multidimensional array. Elements W they must be non-negative.
If a weighing scheme is specified, then the function mean returns a weighted average value, which is useful when the values in the input data have varying degrees of importance or the input data is asymmetric.
If W — vector, it should have the same length as the working dimension. Otherwise W must have the same size as the input data.
| Типы данных |
|
Output arguments
# M — average value
+
scalar | vector | the matrix | multidimensional array
Details
Average values returned as a scalar, vector, matrix, or multidimensional array.
Examples
The average value of the matrix elements
Details
Let’s create a matrix.
import EngeeDSP.Functions: mean
A = [0 1 1; 2 3 2; 1 3 2; 4 2 2]
4×3 Matrix{Int64}:
0 1 1
2 3 2
1 3 2
4 2 2
Calculate the average value of each column.
M = mean(A)
1×3 Matrix{Float64}:
1.75 2.25 1.75
Calculate the average value of each row.
M = mean(A,2)
4×1 Matrix{Float64}:
0.6666666666666666
2.3333333333333335
2.0
2.6666666666666665
Calculate the average value of all the elements of the matrix.
M = mean(A,"all")
1.9166666666666667