## ½ Reshape

Two-argument form See also one-argument form Shape of

Forms the data in the right-hand argument into the 'shape' specified in the left- hand argument which must be a simple numeric scalar or vector. Excess elements are ignored. If there are not enough the data wraps around

                 2 3 ½ 1 2 3 4 5 6       (The numbers 1 to 6 are to be formed
           1 2 3                          into 2 rows and 3 columns)
           4 5 6

                 3 6 ½ 'ABCDEFGHIJKL'    (The 12 characters 'A' to 'L' are to
           ABCDEF                         be formed into 3 rows of 6 columns.
           GHIJKL                         Since there aren't enough different
           ABCDEF                         characters for 3 rows, the last row
                                          repeats the first 6 characters)

                 2 2 ½ 1 2 3 4 5         (The numbers 1 to 5 are to be formed
           1 2                            into 2 rows of 2 columns. The super-
           3 4                            fluous number is ignored)
                 3½'ABC'                 (Simple right argument)
           ABC
                 3½›'ABC'                (Nested right argument is copied 3 times)
           ABC ABC ABC
                 X„6                      (A single number is put in X and its size
                 ½X                       is asked. Since the number has no dimensions
                                          dimensions, the result is an empty vector)
                 X„1½6                    The same number is put in X, but
                 X                        is formed into a 1-element vector. When
           6                              displayed, X contains 6, but its
                 ½X                       size is 1 since it was defined as a
           1                              vector and has the dimension of length)

To produce an empty array (for example to initialise a variable) the right argument may be any value and the left argument must contain at least one zero (corresponding to the empty axis or axes of the result).

                 ½0 33½3
           0 33
                 ½0 45½'A'
           0 45

The empty array has a prototype (see Chapter 1) which is the prototype of the right argument.

If, conversely, the right argument is an empty array, the prototype of the right argument occupies each position of the result.

                 10½¼0
           0 0 0 0 0 0 0 0 0 0
                 ' '=2 3½''              (Note the convention of using ''
           1 1 1                          to indicate a character empty vector)
           1 1 1

Since a scalar has no shape, a scalar can be produced by using an empty vector left argument to ½:

                 X„(¼0)½1½6              (We deliberately create a vector -
                 X                        1½6 - which is then forced to be a
           6                              scalar
                 ½½X
           0

We could have equally used «½ to produce the scalar (see Zilde).

½ can be used for selective specification.

                 ALF
           ABCDEFGHIJKLMNOPQRSTUVWXYZ
                 (5½ALF)„'.....'         (First 5 elements selected and used in
                 ALF                      the specification)
           .....FGHIJKLMNOPQRSTUVWXYZ

Topic: APLX Help : Help on APL language : APL Primitives : ½ Reshape

[ Previous | Next | Contents | Index ]