# From (boxed indexes)

If the left argument of { is boxed, then it is opened and each of its items gives the indexes along successive axes of the right argument. This can be used to select any subarray from an array.

m =. i. 3 4 m 0 1 2 3 4 5 6 7 8 9 10 11 (< 1 2) { m 6

The opened left argument is the list 1 2. The first item is 1, and it is used as the index of the 1st axis; the second item is 2, and it is used as the index of the 2nd axis. The 1 selects the list 4 5 6 7 and the 2 selects 6 from that list.

If there are fewer items in the list than there are axes, then all of the trailing axes are selected.

(<1) { m 4 5 6 7

This is more interesting with a higher rank array.

d =. i.2 3 4 d 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 (<1 2 3) { d NB. plane 1, row 2, column 3 23 (<1 2) { d NB. plane 1, row 2, all columns 20 21 22 23

So far the items in the list of indexes for each axis has been an atom and selects only one index. What if you want more than one index?

If an item in the list of indexes is boxed, then it is a list of indexes for that axis.

Suppose you want to select from m the table of atoms that are in rows 0 2, and columns 0 2 3. That is, the table:

col-0 col-2 col-3 row-0 0 2 3 row-2 8 10 11

The indexes for the axes are the list:

0 2 ; 0 2 3 +---+-----+ |0 2|0 2 3| +---+-----+

That list of indexes needs to be boxed so that each item will be treated as indexes into the successive axes. The 0 2 selects rows (1st axis) and the 0 2 3 selects columns (2nd axis).

< 0 2 ; 0 2 3 +-----------+ |+---+-----+| ||0 2|0 2 3|| |+---+-----+| +-----------+ (< 0 2 ; 0 2 3) { m 0 2 3 8 10 11 (< 0 1 ; 0 2 ; 2 3) { d 2 3 10 11 14 15 22 23

Again, if there are fewer items than axes, then all of the trailing axes are selected.

(< 0 1 ; 0 2) { d 0 1 2 3 8 9 10 11 12 13 14 15 20 21 22 23

Frequently the desired subarray includes all of an axis that is not a trailing axis. This could be done by giving all indexes for that axis.

(< 0 1 2 ; 2 3) { m 2 3 6 7 10 11

This may be inconvenient in a real application where it would necessary to calculate the indexes. For this reason, a boxed empty list, <'', indicates that all indexes in the axis are selected.

< (<'') ; 2 3 +--------+ |+--+---+| ||++|2 3|| ||||| || ||++| || |+--+---+| +--------+

The above, used as the left argument will select all indexes along the first axis because the first item is a boxed empty list, and indexes 2 and 3 along the 2nd axis.

(< (<'');2 3) { m 2 3 6 7 10 11

The boxed empty list is so useful that the primitive a: is defined as <'' . So, the above can be simplified.

(< a: ; 2 3) { m 2 3 6 7 10 11

The above can be even more easily expressed with the " (rank) conjunction.

2 3 {"1 m 2 3 6 7 10 11

Primer Index Hover to reveal titles - Click to access - Current page is highlighted | ||||||||||||||||||||||||

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | ✅ |

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | ✅ | ||||||

45 | 46 | 47 | 48 | ✅ | ||||||||||||||||||||

50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | ✅ | ||||||||||||||||

59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | ✅ | |||||||

77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | ✅ | |||||

97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | ✅ |