Next Previous Up Contents
Next: Arithmetic
Up: General Functions
Previous: Times

### B.1.6 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:

- Aggregating operations, which map an array value to a scalar, including `size`, `count`, `countTrue`, `maximum`, `minimum`, `sum`, `mean`, `median`, `quantile`, `stdev`, `variance`, `join`.
- Operations on one or more arrays which produce array results, including `add`, `subtract`, `multiply`, `divide`, `reciprocal`, `condition`.
- The function `array`, which lets you assemble an array value from a list of scalar numbers. This can be used with the aggregating functions here, but it's generally easier to use the corresponding functions from the `Lists` class.

`sum( array )`
  Returns the sum of all the non-blank elements in the array. If `array` is not a numeric array, `null` is returned.
  - `array` (Object): array of numbers
  - return value (floating point): sum of all the numeric values in `array`
`mean( array )`
  Returns the mean of all the non-blank elements in the array. If `array` is not a numeric array, `null` is returned.
  - `array` (Object): array of numbers
  - return value (floating point): mean of all the numeric values in `array`
`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.
  - `array` (Object): array of numbers
  - return value (floating point): variance of the numeric values in `array`
`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.
  - `array` (Object): array of numbers
  - return value (floating point): standard deviation of the numeric values in `array`
`minimum( array )`
  Returns the smallest of the non-blank elements in the array. If `array` is not a numeric array, `null` is returned.
  - `array` (Object): array of numbers
  - return value (floating point): minimum of the numeric values in `array`
`maximum( array )`
  Returns the largest of the non-blank elements in the array. If `array` is not a numeric array, `null` is returned.
  - `array` (Object): array of numbers
  - return value (floating point): maximum of the numeric values in `array`
`median( array )`
  Returns the median of the non-blank elements in the array. If `array` is not a numeric array, `null` is returned.
  - `array` (Object): array of numbers
  - return value (floating point): median of the numeric values in `array`
`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.
  - `array` (Object): array of numbers
  - `quant` (floating point): number in the range 0-1 deterining which quantile to calculate
  - return value (floating point): quantile corresponding to `quant`
`size( array )`
  Returns the number of elements in the array. If `array` is not an array, zero is returned.
  - `array` (Object): array
  - return value (integer): size of `array`
`count( array )`
  Returns the number of non-blank elements in the array. If `array` is not an array, zero is returned.
  - `array` (Object): array (may or may not be numeric)
  - return value (integer): number of non-blank elements in `array`
`countTrue( array )`
  Returns the number of true elements in an array of boolean values.
  - `array` (array of boolean): array of true/false values
  - return value (integer): number of true values in `array`
`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.
  - `array` (Object): array of numbers or strings
  - `joiner` (String): text string to interpose between adjacent elements
  - return value (String): string composed of `array` elements separated by `joiner` strings
`add( array1, array2 )`
  Returns the result of adding two numeric arrays element by element. Both arrays must be numeric, and the arrays must have the same length. If either of those conditions is not true, `null` is returned. The types of the arrays do not need to be the same, so for example it is permitted to add an integer array to a floating point array.
  - `array1` (Object): first array of numeric values
  - `array2` (Object): second array of numeric values
  - return value (array of floating point): element-by-element sum of `array1` and `array2`, the same length as the input arrays
`add( array, constant )`
  Returns the result of adding a constant value to every element of a numeric array. If the supplied `array` argument is not a numeric array, `null` is returned.
  - `array` (Object): array input
  - `constant` (floating point): value to add to each array element
  - return value (array of floating point): array output, the same length as the `array` parameter
`subtract( array1, array2 )`
  Returns the result of subtracting one numeric array from the other element by element. Both arrays must be numeric, and the arrays must have the same length. If either of those conditions is not true, `null` is returned. The types of the arrays do not need to be the same, so for example it is permitted to subtract an integer array from a floating point array.
  - `array1` (Object): first array of numeric values
  - `array2` (Object): second array of numeric values
  - return value (array of floating point): element-by-element difference of `array1` and `array2`, the same length as the input arrays
`multiply( array1, array2 )`
  Returns the result of multiplying two numeric arrays element by element. Both arrays must be numeric, and the arrays must have the same length. If either of those conditions is not true, `null` is returned. The types of the arrays do not need to be the same, so for example it is permitted to multiply an integer array by a floating point array.
  - `array1` (Object): first array of numeric values
  - `array2` (Object): second array of numeric values
  - return value (array of floating point): element-by-element product of `array1` and `array2`, the same length as the input arrays
`multiply( array, constant )`
  Returns the result of multiplying every element of a numeric array by a constant value. If the supplied `array` argument is not a numeric array, `null` is returned.
  - `array` (Object): array input
  - `constant` (floating point): value by which to multiply each array element
  - return value (array of floating point): array output, the same length as the `array` parameter
`divide( array1, array2 )`
  Returns the result of dividing two numeric arrays element by element. Both arrays must be numeric, and the arrays must have the same length. If either of those conditions is not true, `null` is returned. The types of the arrays do not need to be the same, so for example it is permitted to divide an integer array by a floating point array.
  - `array1` (Object): array of numerator values (numeric)
  - `array2` (Object): array of denominator values (numeric)
  - return value (array of floating point): element-by-element result of `array1[i]/array2[i]` the same length as the input arrays
`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.
  - `array` (Object): array input
  - return value (array of floating point): array output, the same length as the `array` parameter
`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`.

  - `flagArray` (array of boolean): array of boolean values
  - `trueValue` (floating point): output value corresponding to an input true value
  - `falseValue` (floating point): output value corresponding to an input false value
  - return value (array of floating point): output numeric array, same length as `flagArray`
`array( values, ... )`
  Returns a floating point numeric array built from the given arguments.
  - `values` (floating point, one or more): one or more array elements
  - return value (array of floating point): array
`intArray( values, ... )`
  Returns an integer numeric array built from the given arguments.
  - `values` (integer, one or more): one or more array elements
  - return value (array of integer): array
`stringArray( values, ... )`
  Returns a String array built from the given arguments.
  - `values` (String, one or more): one or more array elements
  - return value (array of String): array

Next Previous Up Contents
Next: Arithmetic
Up: General Functions
Previous: Times

TOPCAT - Tool for OPerations on Catalogues And Tables
Starlink User Note253
TOPCAT web page: http://www.starlink.ac.uk/topcat/
Author email: m.b.taylor@bristol.ac.uk
Mailing list: topcat-user@jiscmail.ac.uk