APLX Help : Help on APL language : APL Primitives : ⍴ 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
ALF ABCDEFGHIJKLMNOPQRSTUVWXYZ (5⍴ALF)←'.....' (First 5 elements selected and used in ALF the specification) .....FGHIJKLMNOPQRSTUVWXYZ |
|
APLX Help : Help on APL language : APL Primitives : ⍴ Reshape
|
Copyright © 1996-2010 MicroAPL Ltd