Array functions


Array function

 

Description

 

array_size(arg)

Returns the total number of elements in arg.

array_dims(arg)

Returns the dimensions of the array specified in arg.

combine_array(arg1...)

Combines arg1, arg2, ... The arrays must have the same number of dimensions, n, and the same size in the first n-1 dimensions. The function returns an n-dimension array, where the size in the first n-1 dimensions is the same as the source arrays, and the size of the nth dimension is the sum of the sizes of the source arrays' nth dimension.

concat_array( arg1 , ....

Concatenates arg1, arg2, ... to create one array with dimensions equal to the sum of dimensions of all the arrays.

index_of(arg)

Returns the index of the current object in the array of groups specified by arg. This function must be used by an object that is in a group in the array of groups specified by arg. It is used to create connections between objects in two parallel arrays of groups.

init_array(size,start,end)

Returns a one-dimensional array of size elements that range in ascending order from start to end.

magnitude(arg)

Returns the magnitude (square root of sum of squares) of each column in arg. The function returns an n-1 dimension array, where n is the number of dimensions in arg.

max_array(arg)
max_array(arg, f, v)

Returns (in a one-dimensional array) the maximum value found in each column in the array arg.

If the array has null values, you can include two additional arguments, setting flag f to 1 to indicate that the function should ignore null values, and v to the number that represents a null value. By default, f is 0, meaning that the function operates on all array values.

min_array(arg)
min_array(arg, f, v)

Like max_array, but returns the minimum value of each column in array arg .

prod(arg1...)

Returns the product of all of the elements in arg1, arg2, ...

sum(arg1...)

Returns the sum of all of the elements in arg1, arg2, ...

sum_array(arg1)

Creates a new array, each element of which is a sum of all the previous elements in the original array.

 

 

Note the following:

•      Usage -- Functions returning a single value can be used in a scalar or array expression. Functions returning an array can be used only in an array expression.

•      Arguments -- Arguments are typically array expressions, such as array literals or references to array objects. But they can be scalar expressions, in which case they are treated as one-element arrays.

•      Presenting scalars as an array literal -- With an array literal, you can present a set of scalar expressions as a single array, which you can then use as an argument in an array function like max_array.

Examples


-> int x = 10;
-> int y = 20;
-> int z = 3;
-> int a = max_array ({x, y, z});
-> $int a
20


-> float x[2][3] = {{1,2,3},{4,5,6}};
-> float y[2][2] = {{7,8},{9,10}};
-> int a => array_size(x);
-> $int a
6


-> float a[] => combine_array(x,y);
-> $get_array a
{{1,2,3,7,8},{4,5,6,9,10}}
-> $array_dims a
ndim=2 [2][5]


-> int a1[3]={1,2,3};
-> int a2[3]={5,6,7};
-> int a3[3]={8,9,10};
-> int c[] => concat_array(a1,a2,a3);
-> $get_array c
{1,2,3,5,6,7,8,9,10}


-> float a[] => magnitude(x);
-> $get_array a
{3.74166,8.77496}


-> float a => max_array(x);
-> $real a
6.000000


-> float a => prod(x,y)
-> $real a
3628800.000000


int a[4]={1,2,3,4};
int b[] => sum_array(a);
$get_array b
{1,3,6,10}