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:
size
,
count
,
countTrue
,
maximum
,
minimum
,
sum
,
mean
,
median
,
quantile
,
stdev
,
variance
,
join
.
add
,
subtract
,
multiply
,
divide
,
reciprocal
,
condition
,
slice
,
pick
.
Mostly these work on any numeric array type and return
floating point (double precision) values,
but some of them (slice
, pick
)
have variants for different array types.
array
,
which lets you assemble a floating point array value from
a list of scalar numbers.
There are variants (intArray
, stringArray
)
for some different array types.
sum( array )
array
is not a numeric array, null
is returned.
array
(Object): array of numbersarray
mean( array )
array
is not a numeric array, null
is returned.
array
(Object): array of numbersarray
variance( array )
array
is not a numeric array,
null
is returned.
array
(Object): array of numbersarray
stdev( array )
array
is not a numeric array,
null
is returned.
array
(Object): array of numbersarray
minimum( array )
array
is not a numeric array, null
is returned.
array
(Object): array of numbersarray
maximum( array )
array
is not a numeric array, null
is returned.
array
(Object): array of numbersarray
median( array )
array
is not a numeric array, null
is returned.
array
(Object): array of numbersarray
quantile( array, quant )
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 numbersquant
(floating point): number in the range 0-1 deterining which quantile
to calculatequant
size( array )
array
is not an array, zero is returned.
array
(Object): arrayarray
count( array )
array
is not an array, zero is returned.
array
(Object): array (may or may not be numeric)array
countTrue( array )
array
(array of boolean): array of true/false valuesarray
join( array, joiner )
array
is not an array, null is returned.
array
(Object): array of numbers or stringsjoiner
(String): text string to interpose between adjacent elementsarray
elements separated by
joiner
stringsjoin(array(1.5,2.1,-3.9), "; ") = "1.5; 2.1; -3.9"
dotProduct( array1, array2 )
array1
(Object): first arrayarray2
(Object): second arraydotProduct(array(3,4,5), array(1,2,3)) = 26
add( arrayOrScalar1, arrayOrScalar2 )
If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.
arrayOrScalar1
(Object): first numeric array/scalararrayOrScalar2
(Object): second numeric array/scalararrayOrScalar1 + arrayOrScalar2
,
the same length as the input array(s)add(array(1,2,3), array(0.1,0.2,0.3))
= [1.1, 2.2, 3.3]
add(array(1,2,3), 10) = [11,12,13]
subtract( arrayOrScalar1, arrayOrScalar2 )
If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.
arrayOrScalar1
(Object): first numeric array/scalararrayOrScalar2
(Object): second numeric array/scalararrayOrScalar1 - arrayOrScalar2
,
the same length as the input array(s)subtract(array(1,2,3), array(0.1,0.2,0.3))
= [0.9, 1.8, 2.7]
subtract(array(1,2,3), 1.0)
= [0, 1, 2]
multiply( arrayOrScalar1, arrayOrScalar2 )
If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.
arrayOrScalar1
(Object): first numeric array/scalararrayOrScalar2
(Object): second numeric array/scalararrayOrScalar1 * arrayOrScalar2
,
the same length as the input array(s)multiply(array(1,2,3), array(2,4,6)) = [2, 8, 18]
multiply(2, array(1,2,3)) = [2, 4, 6]
divide( arrayOrScalar1, arrayOrScalar2 )
If the arguments are not as expected (e.g. arrays of different lengths, both scalars, not numeric) then null is returned.
arrayOrScalar1
(Object): first numeric array/scalararrayOrScalar2
(Object): second numeric array/scalararrayOrScalar1 / arrayOrScalar2
,
the same length as the input array(s)divide(array(0,9,4), array(1,3,8)) = [0, 3, 0.5]
divide(array(50,60,70), 10) = [5, 6, 7]
reciprocal( array )
array
argument is not a numeric array,
null
is returned.
array
(Object): array inputarray
parameterreciprocal(array(1,2,0.25) = [1, 0.5, 4]
condition( flagArray, trueValue, falseValue )
This has the same effect as applying the expression
outArray[i] = flagArray[i] ? trueValue : falseValue
.
flagArray
(array of boolean): array of boolean valuestrueValue
(floating point): output value corresponding to an input true valuefalseValue
(floating point): output value corresponding to an input false valueflagArray
condition([true, false, true], 1, 0) = [1, 0, 1]
constant( n, value )
Note:
This documents the double-precision version of the routine.
Corresponding routines exist for other data types
(float
, long
, int
,
short
, byte
).
n
(integer): size of output arrayvalue
(floating point): value of every element in the output arrayn
-element array with every element set to
value
constant(5, 23.5) = [23.5, 23.5, 23.5, 23.5, 23.5]
slice( array, i0, i1 )
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
).
array
(array of floating point): input arrayi0
(integer): index of first element, inclusive
(may be negative to count back from the end)i1
(integer): index of the last element, exclusive
(may be negative to count back from the end)i0
and i1
slice(array(10,11,12,13), 0, 3) = [10, 11, 12]
slice(array(10,11,12,13), -2, 999) = [12, 13]
pick( array, indices, ... )
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
).
array
(array of floating point): input arrayindices
(integer, one or more): one or more index into the input array
(may be negative to count back from the end)indices
pick(array(10,11,12,13), 0, 3) = [10, 13]
pick(array(10,11,12,13), -1, -2, -3)
= [13, 12, 11]
arrayFunc( expr, inArray )
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.
expr
(String): expression mapping input to output array valuesinArray
(Object): input arrayinArray
, or null for a bad expr
arrayFunc("3*x",array(0,1,2,3,NaN))
= [0, 3, 6, 9, NaN]
arrayFunc("pow(2,i)+x", array(0.5,0.5,0.5,0.5))
= [1.5, 2.5, 4.5, 8.5]
intArrayFunc( expr, inArray )
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.
expr
(String): expression mapping input to output array valuesinArray
(Object): input arrayinArray
, or null for a bad expr
intArrayFunc("-x",sequence(5))
= [0, -1, -2, -3, -4]
indexOf( array, item )
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
).
array
(array of Object): array which may contain the supplied itemitem
(Object): entry to look for in the arrayitem
in array
,
or -1indexOf(stringArray("QSO", "BCG", "SNR"), "BCG")
= 1
indexOf(stringArray("QSO", "BCG", "SNR"), "TLA")
= -1
sequence( n )
See also the loop
functions, which provide
similar functionality.
n
(integer): length of arrayn
-element array,
(0, 1, 2, ... n
-1)sequence(4) = (0, 1, 2, 3)
sequence( n, start, step )
See also the loop
functions, which provide
similar functionality.
n
(integer): length of arraystart
(floating point): value of first elementstep
(floating point): increment to apply to each elementn
-element array,
(start, start+step, start+2*step, ... start+(n-1)*step)sequence(4, 100, 0.1) =
(100.0, 100.1, 100.2, 100.3)
loop( start, end )
for (int x = start; x < end; x++)
If you want a floating point array, or one with a non-unit step,
you can use the three-parameter version of
the loop
function.
See also the sequence
functions.
start
(integer): value for first element of output arrayend
(integer): value one greater than last element of output arrayend-start
(or 0) elements
(start, start+1, start+2, ..., end-1)
loop(0, 5) = (0, 1, 2, 3, 4)
loop(5, 0) = ()
loop( start, end, step )
for (double x = start; x < end; x += step)
Note that numerical precision issues may result in the output
array differing from its expected length by 1
(it is generally risky to rely on exact comparison of
floating point values).
If you want to be sure of the number of elements you can use
the sequence
function instead.
start
(floating point): value for first element of output arrayend
(floating point): first value beyond last element of output arraystep
(floating point): increment between output array values; may not be zero(end-start)/step
(or 0) elementsloop(10, 12, 0.5) = (10.0, 10.5, 11.0, 11.5)
loop(0, 10, 3) = (0., 3., 6., 9.)
loop(5, 0, -1) = (5., 4., 3., 2., 1.)
array( values, ... )
values
(floating point, one or more): one or more array elementsintArray( values, ... )
values
(integer, one or more): one or more array elementsstringArray( values, ... )
values
(String, one or more): one or more array elements