>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Primer

# Amend } (modify selected)

Amend is an adverb whose result is a dyad that is used to modify an array. The left argument of amend is usually a noun. Let's look at an example:

       change_index_two =. 2}

The verb `change_index_two` is used dyadically. Its right argument is the original data and the left argument is a new value for index position `2`.

       15 change_index_two 5 6 7 8
    5 6 15 8

       30 change_index_two 23 18 17
    23 18 30

       'b' change_index_two 'cat'
    cab

       15 (2}) 5 6 7 8
    5 6 15 8

       30 (2}) 23 18 17
    23 18 30

       'b' 2} 'cat'
    cab

This extends in ways that you might expect.

       23 (1 4}) 7 7 7 7 7
    7 23 7 7 23

       23 24 (1 4}) 7 7 7 7 7
    7 23 7 7 24

       'bet' 2 5 8} 'cattumbiz'
    cabtuebit

In general an amend `x s} y` is defined as:

> The result is formed by replacing by `x` those parts of `y` that are selected by `s`. The `s` argument to `}` is treated the same way as the left argument of the verb `{` .

Amend allows us to give selected parts of an array new values. The amend argument gives the indexing information about what data to modify. This selects the same elements to be modified as it would if used as the left argument to the dyad verb `{` .

If you understand from, then amend is quite simple.

       m =. i. 3 4
       1 { m
    4 5 6 7

       23 23 23 23 (1}) m
     0  1  2  3
    23 23 23 23
     8  9 10 11

       23 (1}) m
     0  1  2  3
    23 23 23 23
     8  9 10 11

You can first use the selection information to see what data is to be modified.

       1 2 { m
    4 5  6  7
    8 9 10 11

The selected data is a subarray of shape `2 4` . So you need a subarray of shape `2 4` to replace the selected data.

      (2 4 $ 23 23 23 23 24 24 24 24) (1 2}) m
     0  1  2  3
    23 23 23 23
    24 24 24 24

Suppose you want to modify the subarray that is selected as rows `1` and `2`, and columns `0` and `3` with the value `12`.

       12 ((<1 2;0 3)}) m
     0 1  2  3
    12 5  6 12
    12 9 10 12

Modify that subarray by replacing it with the array in the left argument.

       (2 2 $ 23 24 25 26) ((<1 2;0 3)}) m
     0 1  2  3
    23 5  6 24
    25 9 10 26

>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Primer