/
subarray

subarray

The subarray operator produces a result array by selecting a contiguous area of cells.

Synopsis

subarray(array,low_coord1 [,low_coord2,...], high_coord1 [,high_coord2,...]);

Summary

The subarray operator accepts an input array and a set of coordinates specifying a region within the array. The result is an array whose shape is defined by the boundary coordinates specified by the subarray arguments. 

The between operator is similar, except that it returns an array with the same shape as the input. 

Note the following:

  • The number of coordinate pairs (low_coord, high_coord) in the input must equal the number of dimensions in the array.
  • Instead of a coordinate value, you can substitute null. SciDB interprets the null syntax as the minimum or maximum coordinate value for that dimension in that location.  
  • The dimensions in the result array begin at 0, even if the dimensions in the input array do not.
  • The chunk interval for each dimension of the resulting array are the same as the input array.

Example

To select the values from the last two columns and the last two rows of a 4×4 array, do the following:

  1. Create and store an array called m4x4 with the values 0-15:

    AFL% store(build(<val:double>[i=0:3; j=0:3], i*4+j), m4x4);


    The output is:

    {i,j} val
    {0,0} 0
    {0,1} 1
    {0,2} 2
    {0,3} 3
    {1,0} 4
    {1,1} 5
    {1,2} 6
    {1,3} 7
    {2,0} 8
    {2,1} 9
    {2,2} 10
    {2,3} 11
    {3,0} 12
    {3,1} 13
    {3,2} 14
    {3,3} 15
  2. Return an array containing the cells that were in both the last two columns and the last two rows on m4x4:

    AFL% subarray(m4x4,2,2,3,3); 

    Observe the starting value of 0 for dimensions, i and j. 

    The output is:

    {i,j} val
    {0,0} 10
    {0,1} 11
    {1,0} 14
    {1,1} 15
  3. Show the schema of the resulting array. Observe the new shape of the resulting array.

    AFL% show('subarray(m4x4,2,2,3,3)','afl');


    The output is:

    {i} schema
    {0} 'm4x4@1<val:double>[i=0:1:0:1000; j=0:1:0:1000]'
  4. Remove the example array.

    remove(m4x4);