Writing box_amend for a 'single' case,
Where left is (scatind,<newvals), right arg is >firstcell...

box_amend =: 4 : 0
(>{:x) (}:x) } y
)

Then the left arg for eg the first cell is:
   ] lf =: (<"1]>0{idx), 0{contents
+---+---+---+---+---+---+---+--------------------+
|0 1|0 2|3 0|3 2|4 0|5 0|5 1|46 99 23 62 42 44 12|
+---+---+---+---+---+---+---+--------------------+
   ] lf box_amend >0{m   NB: Right arg is rect array
 0 46 99
 0  0  0
 0  0  0
23  0 62
42  0  0
44 12  0

So looped result is now done under 'each' with a simple restructure of your
index and contents as...(scatind1,<contents1);(scatind2,<contents2) etc
    (tidx ,each <"0 contents) box_amend each m
+--------+----------+
| 0 46 99|46 0  0  0|
| 0  0  0| 0 0  0 99|
| 0  0  0| 0 0  0  0|
|23  0 62| 0 0  0  0|
|42  0  0| 0 0 23 62|
|44 12  0|          |
+--------+----------+

Regards, Rob Hodgkinson


On 30/03/08 2:27 PM, "Sherlock, Ric" <[EMAIL PROTECTED]> wrote:

>I want to amend scattered indexes of a boxed list of arrays (m).

I can do it using amendloop below, but want to get rid of the loop if I can.

   ]m=: (6 3$0);5 4$0
+-----+-------+
|0 0 0|0 0 0 0|
|0 0 0|0 0 0 0|
|0 0 0|0 0 0 0|
|0 0 0|0 0 0 0|
|0 0 0|0 0 0 0|
|0 0 0|       |
+-----+-------+

   idx=: 7 2$ 0 1 0 2 3 0 3 2 4 0 5 0 5 1
   ]idx=: idx;4 2$ 0 0 1 3 4 2 4 3
+---+---+
|0 1|0 0|
|0 2|1 3|
|3 0|4 2|
|3 2|4 3|
|4 0|   |
|5 0|   |
|5 1|   |
+---+---+
   ]contents=: (7?.100);4?.100
+--------------------+-----------+
|46 99 23 62 42 44 12|46 99 23 62|
+--------------------+-----------+

   amendloop=: 3 : 0
 n=.''
 for_cnt. contents do.
   n=.n,< (>cnt) (<"1 cnt_index{::idx) } cnt_index{::m
 end.
)

   amendloop ''
+--------+----------+
| 0 46 99|46 0  0  0|
| 0  0  0| 0 0  0 99|
| 0  0  0| 0 0  0  0|
|23  0 62| 0 0  0  0|
|42  0  0| 0 0 23 62|
|44 12  0|          |
+--------+----------+

I imagine it should be something along the lines of:
  contents (<"1 each idx)} each m

But that gives a length error. Any ideas?


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

Reply via email to