{ encompasses everything performed by bracket indexing in other languages. The ranks are 0 _ , that is, x{y can be considered individually for each scalar in x and for y in toto, with the overall result constructed from the individual results in the same way as for all other functions. For scalar x then: >x is a scalar or a list, and r=:>j{,>x are the indices for axis j. r may be integers in the range i.&.(+&n)n=:j{$y, which selects cells n|r, or r may be boxed integers in that range, in which case the selected cells are all except those in n|r. Thus: |
z=: 0{y=: 3 3 3$'ABCDEFGHIJKLMNOPQRSTUVWXYZ]' ibbb=: <ibb=: <ib=: <i=: 1 _1 jbbb=: <jbb=: <jb=: <j=: 2 1 ijbbb=: <ijbb=: <ijb=: <ij=: 2 2$i,j (] ; i&{ ; ib&{ ; ibb&{ ; ibbb&{) z +-----------------+ �ABC�DEF�F�DEF�ABC� �DEF�GHI� �GHI� � �GHI� � � � � +-----------------+ ijb{y �rank error � ijb {y (] ; i&{ ; ijbb&{ ; ijbbb&{) z +---------------+ �ABC�DEF�DEF�ABC� �DEF�GHI�GHI� � �GHI� � � � � � �GHI� � � � �DEF� � +---------------+
The amend adverb } applied to an index produces a function that replaces the selected part of the right argument by the left argument. For example: |
'*' ib} z ABC DE* GHI ('def',:'ghi') i} z ABC def ghi (] ; i&{ ; ib&{ ; ibb&{ ; ibbb&{)"2 y +-----------------+ �ABC�DEF�F�DEF�ABC� �DEF�GHI� �GHI� � �GHI� � � � � +---+---+-+---+---� �JKL�MNO�O�MNO�JKL� �MNO�PQR� �PQR� � �PQR� � � � � +---+---+-+---+---� �STU�VWX�X�VWX�STU� �VWX�YZ]� �YZ]� � �YZ]� � � � � +-----------------+ $(<<'') { z 0 3 $(<a:) { z 0 3
Indexing on higher-rank arrays may be illustrated by the argument y: |
]k=: <1 2;a:;0 2 +------------+ �+----------+� ��1 2�++�0 2�� �� ���� �� �� �++� �� �+----------+� +------------+ y ; k{y +------+ �ABC�JL� �DEF�MO� �GHI�PR� � � � �JKL�SU� �MNO�VX� �PQR�Y]� � � � �STU� � �VWX� � �YZ]� � +------+
The following examples further illustrate the use of the indexing function. For each example, it may be instructive to plug the values into the expression r=:>j{,>x and work out the result.
|