APLX Help : Help on APL language : APL Primitives : / Compress, Replicate
|
|
![]() |
|
When used with a simple numeric scalar or vector operand the CompressionThe left argument is a vector of 1's and 0's. The right argument must conform in length but can be numbers or characters. With a matrix right argument the dimension on which the operator works must be of the same length as the left argument. For each 1 in the left argument, the corresponding element in the right argument is selected. For each 0, the corresponding element in the right argument is ignored. If a single 1 or 0 is used as the left argument, scalar extension ensures that none (0) or all (1) of the right argument is selected. 0 1 0 1 / 'ABCD' (The letters in the same positions as BD the 1's are selected) 1 1 1 1 0/12 14 16 18 20 12 14 16 18 (20 corresponds with the only 0 and is ignored) MARKS←45 60 33 50 66 19 PASS←MARKS≥50 (Each mark greater than or equal to PASS/MARKS 50 puts a 1 in PASS. Those less 60 50 66 than 50 produce 0's. The numbers corresponding to 1's are selected) (MARKS=50)/⍳⍴MARKS (Which members of MARK were 50? 4 The fourth) 1/'FREDERIC' (The 1 or 0 left argument to / FREDERIC can be used to select whether the 0/'FREDERIC' text is selected or not.) (empty) TABLE←2 3 ⍴⍳6 0 1 0/TABLE (Select on the last dimension-columns) 2 5 1 0/[1]TABLE (Select on the first dimension-rows 1 2 3 same operation as 1 0⌿TABLE) The form of ReplicateThis is used to generate multiple copies of elements of the right argument. In addition Replicate can be used either to replace a specified element with one or more instances of that element's prototype or to insert one or more instances of that dimension's prototype. Positive integers in the left argument specify how many copies of each corresponding element in the right argument are wanted. Negative integers in the left argument are used to insert or substitute prototypes. The two alternative mechanisms for this case are: (a) Length of left argument the same as the length of the selected dimension of the right argument. In this case, negative elements in the left argument specify that the corresponding element in the right argument should be replaced by the appropriate quantity of its prototype. (b) If the number of non-negative elements in the left argument is the same as the length of the selected dimension of the right argument, then negative elements in the left argument indicate the position and quantity of prototype elements to insert As usual, a scalar left argument is extended to match the selected axis. If a replication is carried out along an axis of length 1, that axis will be extended. 2 ¯2 2/TABLE (Replace second column of TABLE by 1 1 0 0 3 3 2 columns of 0s - the prototype) 4 4 0 0 6 6 2 ¯2 2 ¯2 2/TABLE (Insert two sets of two columns of 0s) 1 1 0 0 2 2 0 0 3 3 4 4 0 0 5 5 0 0 6 6 VEC←1 2 (2 2⍴⍳4) 3 4 VEC 1 2 1 2 3 4 3 4 1 1 ¯2 1 1/VEC (Insert two copies of the prototype of the 1 2 0 0 0 0 3 4 third element of VEC) 0 0 0 0 1 1 ¯2 1 1 1/VEC (Insert two copies of the prototype of VEC) 1 2 0 0 1 2 3 4 3 4 2 3 2 / 'ABC' AABBBCC 2 / 'DEF' (With a scalar left argument, the 2 is DDEEFF is extended to each element on the right) 5 0 5 / 1 2 3 1 1 1 1 1 3 3 3 3 3 2/TABLE (TABLE as above. Replicate on last 1 1 2 2 3 3 dimension) 4 4 5 5 6 6 2⌿TABLE (Replicate on first dimension. Same as 1 2 3 2/[1]TABLE) 1 2 3 4 5 6 4 5 6 2 3/3 1⍴'ABC' (Last axis, the columns, is extended to AAAAA length 5 to satisfy left argument) BBBBB CCCCC 2 ¯1 2/[2]3 1⍴'ABC' (Last axis extended and blank column AA AA inserted) BB BB CC CC |
|
APLX Help : Help on APL language : APL Primitives : / Compress, Replicate
|
Copyright © 1996-2010 MicroAPL Ltd