While you already have a good answer, let me experiment on this question a
bit more, just for practice.

Let's define the matrix, the function, and the column to be patched:

           m =: _.".,;._2 ]0 : 0
        0 6 3 2
        9 1 7 3
        5 2 9 5
        4 0 9 0
        )
           f =: +:
           c =: 2

Now we can use an amend solution like the ones given above

           m c}~"1 0 f c {"1 m
        0 6  6 2
        9 1 14 3
        5 2 18 5
        4 0 18 0

We can also make this a function of m like this:

           (c}~"1 0 [: f c&{"1) m
        0 6  6 2
        9 1 14 3
        5 2 18 5
        4 0 18 0
           amendcol =: 2 : 'v.}~"1 0 [: u. v.&{"1'
           (f amendcol 2) m
        0 6  6 2
        9 1 14 3
        5 2 18 5
        4 0 18 0

If f is not rank 1, this applies it to the whole column, not to individual
elements or the whole matrix at once:

           (i.@:# amendcol 2) m
        0 6 0 2
        9 1 1 3
        5 2 2 5
        4 0 3 0

Now let's try an alternate solution, this time using agenda.

           m [EMAIL PROTECTED]@.]"0"1 c = i. # m
        0 6  6 2
        9 1 14 3
        5 2 18 5
        4 0 18 0

This however applies f atomwise.  If we want to apply it to the whole
column, we must do a transposition (or is there an easier way?).

           |: (|:m) [EMAIL PROTECTED]@.]"1 0 c = i. # m
        0 6  6 2
        9 1 14 3
        5 2 18 5
        4 0 18 0
           |: (|:m) [`(i.@:#)@[EMAIL PROTECTED]"1 0 c = i. # m
        0 6 0 2
        9 1 1 3
        5 2 2 5
        4 0 3 0

However, as agenda only chooses between using f or not, why don't we try to
use power '^:' instead?

   |: (|:m) [EMAIL PROTECTED]:(0:`]`[)"1 0] c = i. # m
0 6  6 2
9 1 14 3
5 2 18 5
4 0 18 0

We need this stupid '@]' hack only because of the broken semantics of
'u^:(v1`v2)'.  Imo, it should behave like this:

        x u^:(v1`v2) y   be equivalent to  u^:(x v1 y) (x v2 y)

Alternately we could use a different method to circumvent this:

              |: (|:m) f^:((1&{::)`(0&{::))@:;"1 0] c = i. # m
        0 6  6 2
        9 1 14 3
        5 2 18 5
        4 0 18 0

Then, we could just write 'f^:(]`[)' instead of '[EMAIL PROTECTED]:(0:`]`[)'.

ambrus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to