Enclose


One-argument form  See also two-argument form Partition

Enclose produces a scalar from its argument. If the argument is already a simple scalar the result is also a simple scalar, otherwise it has a depth of one greater than the argument.

             TABLE„2 3½¼6
             TABLE
       1 2 3
       4 5 6
             ¦TABLE
       1
             ½›TABLE                 (Enclose produces a scalar)
                                     (Shape of a scalar is an empty vector)
             ½½›TABLE
       0                             (Rank of scalar is 0)
             ¦›TABLE
       2                             (Depth has been increased by 1)

Enclose with axis

When used with an axis specification, enclose will only enclose the axes indicated within the axis specification.

             ›[1]TABLE               (Enclose the  rows , leaving columns)
        1 4  2 5  3 6
             ½›[1]TABLE              (Result is length 3 vector)
       3
             ¦›[1]TABLE              (Depth increased by 1)
       2
             ›[2]TABLE               (Enclose the  columns  leaving rows)
        1 2 3  4 5 6
             ½›[2]TABLE              (Result is length 2 vector)
       2
             ¦›[2]TABLE              (Depth increased by 1)
       2

Enclose with axis can also be used to carry out a rearrangement of its argument (see also ³, transpose) by using a non ascending set of axes in the axis specification. Including all the axes in ascending order is equivalent to enclose.

             ½›[1 2]TABLE            (Same as ›TABLE)
        EMPTY
             ½›[2 1]TABLE            (Scalar result)
        EMPTY
             ›[2 1]TABLE             (Order of axes reversed)
       1 4                           (Columns become rows within the first item
       2 5                            of the result)
       3 6

When the axis specification is an empty vector, enclose with axis has no effect on a simple array, but with non-simple arguments increases the depth of the argument by 1. Each item of the argument is enclosed, but the overall shape is not altered.

             ½TABLE                  (TABLE, as above)
       2 3
             ¦TABLE                  (Depth 1)
       1
             ½›[¼0]TABLE             (Enclose with empty vector axis
       2 3                            specification has no effect)
             ¦›[¼0]TABLE
       1
             TAB„2 2½(¼3) (¼3) 'ABC' 'DE'
             TAB                     (Nested matrix)
        1 2 3  1 2 3
        ABC    DE
             ½TAB                    (Shape 2 2)
       2 2
             ½›[¼0]TAB               (Enclose with empty vector axis
       2 2                            specification preserves shape)
             ¦TAB
       2
             ¦›[¼0]TAB               (Increases depth)
       3

Topic: APLX Help : Help on APL language : APL Primitives : › Enclose
[ Previous | Next | Contents | Index ]