## œ Pick

Two-argument form See also one-argument form Disclose

Pick is used to select an item from its right argument according to the specification contained in its left argument. Each element in the left argument is used to specify successively deeper selections in the right argument. At each level of specification the element in the left argument being used must be of the appropriate shape - a single number for a vector, a two element vector for a matrix and so on.

                 A„'FIRST' 'SECOND' 'THIRD'
                 ½A                      (Three element vector)
           3
                 2œA                     (Pick the second element)
           SECOND
                 2 3œA                   (Pick the third element of the second
           C                              element)
                 A„(1 'FIRST') (2 'SECOND') (3 'THIRD')
                 ½A                      (Three element vector, with each element
           3                              a two element vector)
                 3œA
           3 THIRD                       (Third element selected)
                 3 2œA
           THIRD                         (Second element of third element selected)
                 3 2 1œA
           T                             (First element of second element of third
                                          element)

When operating on arrays with two or more dimensions, care must be taken to ensure that the left argument to œ is correctly formed.

                 TABLE„2 2½(¼3) 'NAMES' (2 2½4 5 6 7) (3 3½'ABCDEFGHI')
                 TABLE
           1 2 3  NAMES

             4 5   ABC
             6 7   DEF
                   GHI

Selection of one of the outermost items from TABLE must be by means of a two element vector (given the shape of TABLE is 2 2), but this selection item must be formed as a scalar to indicate that it refers to the outmost layer.

                 1 2œTABLE
           RANK ERROR
                 1 2œTABLE
                 ^

In the example above, the left argument to pick is interpreted as 'first element from outermost layer' then 'second element from next layer deep'. A correctly formed left argument is:

                 (›1 2)œTABLE
           NAMES
                 (1 2) 2œTABLE
           A                             (Select row 1 column 2, then element 2)
                 (2 1) (2 2)œTABLE       (Select row 2 column 1, then row 2
           7                              column 2)

Pick may be used with selective specification, in which case the whole array picked will be replaced by the object being assigned.

Topic: APLX Help : Help on APL language : APL Primitives : œ Pick

[ Previous | Next | Contents | Index ]