Engee documentation

mean

The average value of the array elements.

Library

EngeeDSP

Syntax

Function call

  • M = mean(A) — returns the average value of the array elements A according to the first dimension, the size of which is not equal to 1.

    • If A — vector, then mean(A) returns the average value of the elements A.

    • If A — the matrix, then mean(A) — vector is a row containing the average value of each column A.

    • If A — a multidimensional array, then mean(A) it operates on the first dimension A, the size of which is not equal to 1 considering the elements as vectors. Size M in this dimension , it becomes equal to 1, while the dimensions of all other dimensions remain the same as in A.

  • M = mean(A, "all") — returns the average value for all elements A.

  • M = mean(A, dim) — returns the average value of the dimension dim. For example, if A — the matrix, then mean(A,2) returns a column vector containing the average value of each row.

  • M = mean(A, vecdim) — returns the average value for the dimension specified in the vector vecdim. For example, if A — the matrix, then mean(A,[],[1 2]) returns the average value for all elements of the matrix A since each element of the matrix is contained in an array layer defined by the dimensions 1 and 2.

  • 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 default mean includes missing values.

  • M = mean(_, Weight=W) — defines the weighing scheme W and 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, then mean(A) returns A.

  • If A — an empty matrix of size 0 on 0 Then mean(A) returns NaN.

Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Bool

# 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 :

  • mean(A,1) calculates the average value of the elements in each column of the matrix A and returns a vector string of the size 1 on .

mean 1

  • mean(A,2) calculates the average value of the elements in each row of the matrix A and returns a column vector of size 1 on .

mean 2

# 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.

std 3 en

# 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 the M also 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 in M also 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.

You cannot specify this argument if an argument is used. vecdim or the method M = mean(A, "all").

Типы данных

Float32, Float64

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

Additional Info

The average value

Details

For the vector of finite length, consisting of scalar values, the average value is defined as

Weighted average

Details

For the vector of finite length, consisting of scalar quantities, and weighing schemes The weighted average is defined as