AVERAGE function

Synopsis
This function computes the mean (average) of the elements of an array.
Remarks
Variations
AVERAGE(SourceArray)
Returns the average of all elements of the source array.
Parameters
SourceArray

Specifies the array to average.

Supported types: Numeric array; Boolean array.
Returns
Returned types: Numeric.
Examples
1.

In the following example, the function returns 7, the average of all elements of the source array.

AVERAGE([5, 15, 1])
2.

To avoid an error when you pass an empty array to this function, you could use the following expression. Note the example above is encapsulated in the following IF statement.

IF(COUNT([5, 15, 1]) > 0, AVERAGE([5, 15, 1]) , -1)
AVERAGE(SourceArray, StartIndex, Count)
Returns the average of all the elements of a subset of the source array.
Parameters
SourceArray

Specifies the array from which to obtain the elements to average.

Supported types: Numeric array; Boolean array.
StartIndex

Specifies the index of the first element of the subset in the source array.

Supported types: Numeric.
Count

Specifies the number of elements (beginning at StartIndex) to include in the subset of the source array.

Supported types: Numeric.
Returns
Returned types: Numeric.
Examples
1.

The following example calculates the average of the subset of the source array specified by the index and count parameters, [5, 10, 6]. The function returns 7.

AVERAGE([1, 2, 3, 5, 10, 6], 4, 3)
2.

To avoid an error when you pass an empty array to this function, you could use the following expression. Note the example above is encapsulated in the following IF statement.

IF(COUNT([1, 2, 3, 5, 10, 6]) > 0, AVERAGE([1, 2, 3, 5, 10, 6], 4, 3) , -1)
AVERAGE(SourceArray, Expression)
Returns the average of all elements of the source array after performing an expression on each element.
Parameters
SourceArray

Specifies the array to average.

Supported types: Numeric array; Boolean array; String array; Point array; Object array.
Expression

Specifies the expression to apply to each element of the source array.

Supported types: Numeric.
Returns
Returned types: Numeric.
Examples
1.

The following example performs the expression Item/10, which results in array [5, 10, 20, 25]. The function then returns the average 15.

AVERAGE([50, 100, 200, 250], Item/10)
2.

The following example accesses an object array of type BlobFound. The expression extracts the areas of each blob found during the BlobAnalysis step, and the function returns the average of these areas.

AVERAGE(BlobAnalysis.BlobFound, Item.Area)
3.

To avoid an error when you pass an empty array to this function, you could use the following expression. Note that example 2 above is encapsulated in the following IF statement.

IF(COUNT([50, 100, 200, 250]) > 0, AVERAGE(BlobAnalysis.BlobFound, Item.Area) , -1)
AVERAGE(SourceArray, StartIndex, Count, Expression)
Returns the average of all the elements of a subset of the source array after performing an expression on each element.
Parameters
SourceArray

Specifies the array from which to obtain the elements to average.

Supported types: Numeric array; Boolean array; String array; Point array; Object array.
StartIndex

Specifies the index of the first element of the subset in the source array.

Supported types: Numeric.
Count

Specifies the number of elements (beginning at StartIndex) to include in the subset of the source array.

Supported types: Numeric.
Expression

Specifies the expression to apply to each element of the source array.

Supported types: Numeric.
Returns
Returned types: Numeric.
Examples
1.

The following example applies the expression to the subset of the source array specified by the start index and count [50, 100, 60]. This results in array [5, 10, 6]. The function then returns the average 7.

AVERAGE([50, 50, 100, 60, 250], 2, 3, Item/10)
2.

To avoid an error when you pass an empty array to this function, you could use the following expression. Note the example above is encapsulated in the following IF statement.

IF(COUNT([50, 50, 100, 60, 250]) > 0, AVERAGE([50, 50, 100, 60, 250], 2, 3, Item/10) , -1)