Array builtins

Array builtins are designed to supplement the array capabilities of the software. Use these builtins to find the sum, the standard deviation, or the mean across dimensions of arrayed variables. Many of these functions work on array ranges, and there is in-depth discussion of this in Specialized Array Manipulation.

Some of these builtins can also be used for non-arrayed variables.

The array builtins can be applied to either an arrayed variable or an expression. Some can also be applied to conveyors and queues to deal with the elements within the stock.

When an array builtin is applied to an expression, care must be taken to ensure that the intended dimensions are being reduced as expected.

 

This section describes the following builtins:

MEAN(<array or expression>)

The MEAN builtin calculates the arithmetic mean across the elements in the array or expression. The calculation is defined as the sum of the elements, divided by the number of elements in the array.

The MEAN calculation can be done in either an arrayed or a non-arrayed converter or flow.

To report the mean across a subset of the dimensions of the arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension. You can report the arrayed variable's mean in either an arrayed or a non-arrayed converter or flow.

Examples:

Average Salary for Employees = MEAN(Salaries)

Average Salary for Employees in Boston = MEAN(Salaries[Boston,*])

Average Salary for Labor Groups 1 to 3 = MEAN(Salaries[*,1:3])

PROD(<array or expression>)

The PROD builtin calculates the product of all the elements in the array or expression.

To report product across a subset of the dimensions of an arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension, or a range specified (min:max) to report part of the array. You can use the arrayed variable's product in either an arrayed or a non-arrayed variable.

Example:

Interest_Factor[Year] = (1.0 + Interest_Rate[Year])

Compounded_Interest_to_Year[Year] = principal * PROD(Interest_Factor[1:year])

RANK(<arrayed variable>, <rank number>, [<secondary sort array>])

The RANK builtin gives the numerical index of the arrayed variable with the given rank number when the array is sorted in ascending order. The optional secondary sort arrayspecifies the secondary sort field for variables with the same value. The secondary sort array must be the same size as the arrayed variable, or the secondary sort won't occur (this is only enforced when you simulate the model, so you won't be warned).

Example:

If array A contains the values { 6, 2, 8, 5 }

RANK(A, 2) will equal 4 (i.e., the fourth element of array A is the second smallest value)

Using RANK causes the specified array to be sorted once each time step (DT). For multi-dimensional arrays, you can pass one or more dimensions of the array to return the rank of a subset of the array.

Example:

Rank(Salaries[Boston,*],2) returns the rank of the second smallest salary in Boston.

SELF

Use the SELF builtin in conjunction with the SIZE and PREVIOUS builtins to refer to the current variable.

SIZE(<array or expression>)

The SIZE builtin gives the number of elements in the array or expression.

Note: You can also use the SIZE builtin to report the length of a queue.

To get the size or dimension size of an array holding the equation, use the SELF builtin.

Examples:

SIZE(SELF) gives the number of elements in this array.

SIZE(SELF[*, 1]) gives the size of the first dimension of this array.

SIZE(SELF[1, *]) gives the size of the second dimension of this array.

SIZE (<queue>) returns the total number of elements contained in the specified queue-type discrete stock.

SIZE (<conveyor>) returns the total number of slots contained in the specified conveyor-type discrete stock.

STDDEV(<array or expression>)

The STDDEV builtin calculates standard deviation for all the elements in the array or expression.

To report the standard deviation across a subset of the dimensions of an arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension. You can report the arrayed variable's standard deviation in either an arrayed or a non-arrayed converter or flow.

Example:

Standard Deviation of Salary in Boston= STDDEV(Salaries[Boston,*])

SUM(<array or expression>)

The SUM builtin calculates the sum of all the elements in the array or expression.

To report the sum across a subset of the dimensions of an arrayed input variable, specify an asterisk (*) to include all of the elements across a dimension. You can report the arrayed variable's sum in either an arrayed or a non-arrayed converter or flow.

Example:

Total Salary for Employees in Boston = SUM(Salaries[Boston,*])

Concept Link IconSee Also