## Take

Two-argument form See also one-argument form First

The left-hand argument of take specifies how many elements are to be selected from the right-hand argument in each of its dimensions. If the left-hand argument is positive, the elements are selected from the start of the appropriate dimension, if negative, from the end. The result is the data selected.

                 5  'A.S.FREEMAN'
           A.S.F
                 ―7  'A.S.FREEMAN'
           FREEMAN
                 3  22 2 19 12
           22 2 19
                 ―1  22 2 19 12
           12
                 LIST(2 2½Ό4) (Ό10)
                 ½LIST                  (Note that first removes depth)
           2 2
                 ½1LIST                 (Take does not affect the depth)
           1

If the left argument specifies more elements than the right argument contains, all elements are selected and the prototype of the array is added for each missing element:

                 5  40 92 11
           40 92 11 0 0
                 ―540 92 11
           0 0 40 92 11

If the right argument is a matrix, the first number in the left argument specifies the number of rows to be selected, and the second, the number of columns:

                 TABLE  4 3 ½ Ό 12
                 TABLE
            1  2  3
            4  5  6
            7  8  9
           10 11 12
                 2 3  TABLE             (Selects all three columns of the
           1 2 3                          first two rows)
           4 5 6
                 ―1 3  TABLE            (Selects all three columns of the
            10 11 12                      last row)
                 1 2  TABLE             (Selects row 1, columns 1 and 2)
            1 2

The overtake operation on matrices or higher dimensional arrays uses the prototype of the first element of each row already in existence to extend rows. New rows use the array prototype.

                 MAT
             1 A
             B 2
                 ½MAT
           2 2
                 3 3MAT
             1 A 0                       (Extension of row 1 uses row 1 prototype)
             B 2                         (Row 2 prototype is a blank character)
             0 0 0                       (Row 3 is new and uses the array prototype)

Similar considerations apply to higher dimension arrays. Take can be used for selective specification.

### Take used with axis

Take used with the axis operator will select only from the axes specified. Any axis not specified by the axis operator remains unchanged. Each successive element of the left argument indicates how many items to take from the corresponding axis within the axis specification (and from which end).

                 MAT
             1  2  3  4
             5  6  7  8
             9 10 11 12
                 2[1]MAT                (Take the first 2 members of the first
             1 2 3 4                      dimension, the rows, and leave the number
             5 6 7 8                      of columns unchanged)
                 3[2]MAT                (First 3 columns, the second dimension)
             1  2  3
             5  6  7
             9 10 11

Overtake will follow the same rules as for take (see above).

                 TABLE
           1 A 2
           B 3 4
                 3[1]TABLE
           1 A 2                         (New row uses array prototype)
           B 3 4
           0 0 0
                 4[2]TABLE
           1 A 2 0                       (Prototype of row 2 is the blank
           B 3 4                          character)

Topic: APLX Help : Help on APL language : APL Primitives : Take

[ Previous | Next | Contents | Index ]