Kairit Sirts wrote: > Thank you very much! I got a lot smarter. But the trick is still > that I don't need to replace the 0 with 1, but to add 1.
I'd suggest thinking of add as a separate step from replace. For example: m=: 4 4$0 c=: 1 3 3 ; 2; 0; 0 c #/.~@>@[`(~.@>@[)`]}"0 1 m or c (>@[ #/[EMAIL PROTECTED]([EMAIL PROTECTED])`]} ])"0 1 m Or: M=:i. 4 4 M+c #/.~@>@[`(~.@>@[)`]}"0 1 M*0 Put differently, 1 3 3; 2; 0; 0 is a representation of a matrix, and if you convert that to the normal representation for a matrix you can simply add the two matrices. Here's another way to approach this problem of converting the c representation to a more typical representation for the matrix: 4 4$<:#/.~(,i.4 4),4#.;(i.4),.L:0"0 c or 4 4$<:#/.~(i.16),;(4*i.4)+each c Note: I've hard coded 4, 4 4 and 4*4 in this expression because, in the general case, I'm not sure where I should pull those from. I might have used #m, $m and #,m but maybe there's better ways? Note also that in your specific case you might be able to take advantage of other information from your environment to simplify this entire process. The details, of course, depend on what you're trying to do. FYI, -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
