median

The median aggregate returns the median from a set of input values. Available only in the Enterprise Edition.

Synopsis

AQL% SELECT median(attribute) FROM array;
AFL% aggregate(array,median(attribute),dimension_1[,dimension_2]...

Inputs

  • array:  Specifies an array in the SciDb database.
  • median(attribute):  Specifies which attribute to use when performing the median aggregation
  • dimension_n:  Specifies which dimension to use when performing the median aggregation.

Library

The median aggregate resides in the Linear Algebra library. Run the following query to load this library:

AFL% load_library('linear_algebra'); 

Summary

The median aggregate returns the median from a set of input values. The median is the middle number (in a sorted list of numbers). The median value for a set of n values is defined as:

Example

To find the median of each column of a 3×3 matrix, do the following:

  1. Load the appropriate library:

    AFL% load_library('linear_algebra');


    The output is:

    Query was executed successfully
  2. Create an array m3x3:

    AFL% CREATE ARRAY m3x3<val:double>[i=0:2; j=0:2];


    The output is:

    Query was executed successfully
  3. Store values 0–8 in the m3x3 array:

    AFL% store(build(m3x3,i*3+j),m3x3); 


    The output is:

    {i,j} val
    {0,0} 0
    {0,1} 1
    {0,2} 2
    {1,0} 3
    {1,1} 4
    {1,2} 5
    {2,0} 6
    {2,1} 7
    {2,2} 8
  4. Find the median of every column of m3x3 using the attribute val and the dimension j:

    AFL% aggregate(m3x3,median(val),j);  


    The output is:

    {j} val_median
    {0} 3
    {1} 4
    {2} 5 


  5. Remove the m3x3 array:

    AFL% remove(m3x3);


    The output is:

    Query was executed successfully