Size
Size(A)
Size returns the total number of elements in array «A».
When applied to a scalar (a zero-dimensional array), it returns 1.
Size does not count elements that are contained within a reference. So if a reference occurs in a cell of an array, it will be counted as one, even if it points to an array that contains many cells.
Library
Array library
Length of an index
When used on an index, Size(I) returns the length of the index. However, be careful -- if used with a self-indexed array, it is the size of the array, not the size of the index, that is returned. When an array is one-dimensional, these are the same, but a self-indexed array could be multi-dimensional. Two safer ways to obtain the length of an index are:
Size(IndexValue(I))
or
Sum(1, I)
Length of the implicit dimension
All dimensions of an Analytica array correspond to an explicit index object, except for one -- the implicit dimension. See the article Implicit Dimensions for more details.
When «A» has an implicit dimension, its length can be obtained using:
Size(A, listLen: true)
You can also use this to determine the number of repeated parameters supplied to a User-Defined Function. For example:
Function GeoAve(x : ... Number )
Definition: Exp(Sum(Ln(x))/Size(x, ListLen: true))
Array Abstraction Considerations
Although Size does return a result when the number of dimensions of an array changes, this function does not strictly obey the law of array abstraction. This is because it operations over all indexes that are present, rather than only over a set of explicit specified indexes. Because of this, if used inappropriately within a model, incorrect results from Parametric Analyses could result.
In this context, use of Size to find the length of an index or the length of the implicit dimension is a usage that is consistent with the law of array abstraction.
Notes
Inside a dynamic loop, Size(Time)
returns 1. This occurs because in a value context within a dynamic loop, the expression Time
(or @Time
) evaluates to the current time point (or time position), not the full array of time values. Since there is only one time point at a time in a dynamic loop, the size is 1.
This case is worth remembering since it can be kind of confusing when you (incorrectly) attempt to use @Time/Size(Time)
to compute progress, which of course does not produce the desired result. The remedy here is to remember to use Size(IndexValue(Time))
to obtain the index length.
Enable comment auto-refresher