T=. val (<i,j)} T

   'I'(<0 3)}T=.4 4 $ (64+ ?. 16 # 32) { a.
BYII
ZBKH
THZI
_TFW
 

R.E. Boss


-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Yuvaraj Athur Raghuvir
Verzonden: woensdag 2 januari 2008 7:11
Aan: Programming forum
Onderwerp: [Jprogramming] Update a 2-D array in-place?

Hello,

I have a 2-D array T. I want a verb update as follows:
(i;j;val) update T

The result is that the table T is updated with the value val at the location
(i;j)

I did a simple implementation that uses the following algorithm:
a) split T into 3-parts according to rows : rows(i-1) , row(i), rows(i+1) :
b) split row(i) into 3-parts according to columns : row(i)cols(j-1),
row(i)col(j), row(i)cols(j+1)
c) change the value row(i)col(j)
d) reassemble - assemble row(i), assemble T

Clearly, this is not optimal in space.

In my case, I needed to discover row i via a key & key column variables. My
implementation follows

I want to know if it is possible to
(a) update 2-D array in-place ?
(b) generalized for arbitrary dimension arrays?

Thanks,
Yuva


----------- My Simple Implementation --------------- NB.
(key;keycol;valcol;val) updT t updT =: dyad define
    'k kc vc v' =. x
    y1 =. kc {"1 y
    p =. k I.@:=/ y1
    s1 =. p {. y
    s2 =. (>:p) }. y
    r =. p { y
    r1 =. vc {. ,r
    r2 =. (>:vc) }.,r
    r3 =.,: r1,v,r2
    s1,r3,s2
)

   ]T =. 4 4 $ (64+ ?. 16 # 32) { a.
BYIP
ZBKH
THZI
_TFW
   ('Z';0;3; 'I') updT T
BYIP
ZBKI
THZI
_TFW
   ]T =. ?. 4 4 $ 9
3 8 8 4
2 0 2 7
4 2 3 5
1 1 7 2
   (2;0;3;6) updT T
3 8 8 4
2 0 2 6
4 2 3 5
1 1 7 2

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

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

Reply via email to