Next Previous Up Contents
Next: Bits
Up: Functions
Previous: Arithmetic

10.6.2 Arrays

Functions which operate on array-valued cells. The array parameters of these functions can only be used on values which are already arrays (usually, numeric arrays). In most cases that means on values in table columns which are declared as array-valued. FITS and VOTable tables can have columns which contain array values, but other formats such as CSV cannot.

If you want to calculate aggregating functions like sum, min, max etc on multiple values which are not part of an array, it's easier to use the functions from the Lists class.

Note that none of these functions will calculate statistical functions over a whole column of a table.

The functions fall into a number of categories:

sum( array )
Returns the sum of all the non-blank elements in the array. If array is not a numeric array, null is returned.

mean( array )
Returns the mean of all the non-blank elements in the array. If array is not a numeric array, null is returned.

variance( array )
Returns the population variance of all the non-blank elements in the array. If array is not a numeric array, null is returned.

stdev( array )
Returns the population standard deviation of all the non-blank elements in the array. If array is not a numeric array, null is returned.

minimum( array )
Returns the smallest of the non-blank elements in the array. If array is not a numeric array, null is returned.

maximum( array )
Returns the largest of the non-blank elements in the array. If array is not a numeric array, null is returned.

median( array )
Returns the median of the non-blank elements in the array. If array is not a numeric array, null is returned.

quantile( array, quant )
Returns a quantile value of the non-blank elements in the array. Which quantile is determined by the quant value; values of 0, 0.5 and 1 give the minimum, median and maximum respectively. A value of 0.99 would give the 99th percentile.

size( array )
Returns the number of elements in the array. If array is not an array, zero is returned.

count( array )
Returns the number of non-blank elements in the array. If array is not an array, zero is returned.

countTrue( array )
Returns the number of true elements in an array of boolean values.

join( array, joiner )
Returns a string composed of concatenating all the elements of an array, separated by a joiner string. If array is not an array, null is returned.

dotProduct( array1, array2 )
Returns the dot (scalar) product of two numeric arrays. If either argument is not an array, or if the arrays are not of the same length, a blank value is returned.

add( arrayOrScalar1, arrayOrScalar2 )
Returns the element-by-element result of adding either two numeric arrays of the same length, or an array and a scalar considered as if an array of the right length.

If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.

subtract( arrayOrScalar1, arrayOrScalar2 )
Returns the element-by-element result of subtracting either two numeric arrays of the same length, or an array and a scalar considered as if an array of the right length.

If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.

multiply( arrayOrScalar1, arrayOrScalar2 )
Returns the element-by-element result of multiplying either two numeric arrays of the same length, or an array and a scalar considered as if an array of the right length.

If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.

divide( arrayOrScalar1, arrayOrScalar2 )
Returns the element-by-element result of dividing either two numeric arrays of the same length, or an array and a scalar considered as if an array of the right length.

If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.

reciprocal( array )
Returns the result of taking the reciprocal of every element of a numeric array. If the supplied array argument is not a numeric array, null is returned.

condition( flagArray, trueValue, falseValue )
Maps a boolean array to a numeric array by using supplied numeric values to represent true and false values from the input array.

This has the same effect as applying the expression outArray[i] = flagArray[i] ? trueValue : falseValue.

constant( n, value )
Returns a fixed-size array filled with a given constant value.

Note: This documents the double-precision version of the routine. Corresponding routines exist for other data types (float, long, int, short, byte).

slice( array, i0, i1 )
Returns a sub-sequence of values from a given array.

The semantics are like python array slicing, though both limits have to be specified: the output array contains the sequence of elements in the input array from i0 (inclusive) to i1 (exclusive). If a negative value is given in either case, it is added to the length of the input array, so that -1 indicates the last element of the input array. The indices are capped at 0 and the input array length respectively, so a large positive value may be used to indicate the end of the array. If the end index is less than or equal to the start index, a zero-length array is returned.

Note: This documents the double-precision version of the routine. Corresponding routines exist for other data types (float, long, int, short, byte, String, Object).

pick( array, indices, ... )
Returns a selection of elements from a given array.

The output array consists of one element selected from the input array for each of the supplied index values. If a negative value is supplied for an index value, it is added to the input array length, so that -1 indicates the last element of the input array. If the input array is null, null is returned. If any of the index values is out of the range of the extent of the input array, an error results.

Note: This documents the double-precision version of the routine. Corresponding routines exist for other data types (float, long, int, short, byte, String, Object).

arrayFunc( expr, inArray )
Returns a floating-point array resulting from applying a given function expression element-by-element to an input array. The output array is the same length as the input array.

The supplied expression can use the variable "x" to refer to the corresponding element of the input array, and "i" to refer to its (zero-based) index. The various functions and operators from the expression language can all be used, but it is currently not possible to reference other table column values.

If there is an error in the expression, a blank value (not an array) will be returned.

intArrayFunc( expr, inArray )
Returns an integer array resulting from applying a given function expression element-by-element to an input array. The output array is the same length as the input array.

The supplied expression can use the variable "x" to refer to the corresponding element of the input array, and "i" to refer to its (zero-based) index. The various functions and operators from the expression language can all be used, but it is currently not possible to reference other table column values.

If there is an error in the expression, a blank value (not an array) will be returned.

indexOf( array, item )
Returns the position in a supplied array at which a given item appears. The result is zero-based, so if the supplied item is the first entry in the array, the return value will be zero.

If the item does not appear in the array, -1 is returned. If it appears multiple times, the index of its first appearance is returned.

If indexOf(array, item)==n, then array[n] is equal to item.

Note: This documents the Object version of the routine. Corresponding routines exist for other data types (double, float, long, int, short).

sequence( n )
Returns an integer array of a given length with the values 0, 1, 2, ....

array( values, ... )
Returns a floating point numeric array built from the given arguments.

intArray( values, ... )
Returns an integer numeric array built from the given arguments.

stringArray( values, ... )
Returns a String array built from the given arguments.


Next Previous Up Contents
Next: Bits
Up: Functions
Previous: Arithmetic

STILTS - Starlink Tables Infrastructure Library Tool Set
Starlink User Note256
STILTS web page: http://www.starlink.ac.uk/stilts/
Author email: m.b.taylor@bristol.ac.uk
Mailing list: topcat-user@jiscmail.ac.uk