there is this fairly intuitive approach
to2 =: ( [: <"1 [: ,."0/&>/ [: i.@:>: each -~)
to =: 2 : 'm ,@:to2 n'
0 0 to 2 2
┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
│0 0│0 1│0 2│1 0│1 1│1 2│2 0│2 1│2 2│
└───┴───┴───┴───┴───┴───┴───┴───┴───┘
1 (0 0 to 2 2) } i.4 4
1 1 1 3
1 1 1 7
1 1 1 11
12 13 14 15
to make a verb out of it:
toV =: ,@:to2
eval =: 1 : ' a: 1 : m'
advswap =: 2 : (':'; 'u x v eval y')
0 0 to 2 2 (1 advswap '}') i.4 4
1 1 1 3
1 1 1 7
1 1 1 11
12 13 14 15
(0 0 toV 2 2) (1 advswap '}') i.4 4
1 1 1 3
1 1 1 7
1 1 1 11
12 13 14 15
________________________________
From: Sebastian <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Tuesday, October 21, 2014 10:04 AM
Subject: [Jprogramming] Insert a 2 dimensional array to a n dimensional array
Hello,
I have a question similar to the question I had a few weeks before. The
question was how replace single values from a matrix
(http://jsoftware.com/pipermail/programming/2014-September/039225.html).
Now I would like to replace a matrix with at least 2 dimensions with
values from a 2 dimensional array.
The new values should replace the old values from the matrix, like this:
new data:
1 1 1
1 1 1
1 1 1
old data:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
result:
1 1 1 0
1 1 1 0
1 1 1 0
0 0 0 0
The insert position to the matrix should be parameterisable.
Best regards
Sebastian
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm