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