slice

The slice operator produces a result array that is a subset of the source array derived by holding one or more dimension values constant.

Synopsis

slice(array, dimension1, value1 [,dimension2,value2]...);

Summary

The slice operator produces an m-dimensional result array from an n-dimensional source array where n is greater than m. If n is 3 and m is 2, visualize the operation as slicing a specific plane of a 3-D array. The number of dimensions of the result array equals the number of dimensions of the source array minus the number of (dimension, value) pairs you provide as parameters. For each (dimension, value) pair you supply, the value must appear in that dimension in the source array.

Example

To select the middle column from a 3×3 array, do the following:

  1. Create a 3×3 array and fill it with values of 0–8:

    AFL% store(build(<val:double>[i=0:2; j=0:2],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
  2. Select the middle column of m3x3:

    AFL% slice(m3x3,j,1); 


    The output is:

    {i} val
    {0} 1
    {1} 4
    {2} 7 

     

    • Using the between and redimension operators accomplishes the same task, as shown in the following query:

      AFL% redimension(between(m3x3,0,1,2,1),<val:double>[i=0:2]);  


      The output is:

      {i} val
      {0} 1
      {1} 4
      {2} 7

Â