Solution
1 0 2 ⍉ (9÷⍨≢data) 3 3 ⍴ data
Explanation
By using ⍳45
as placeholder data, we can see what is intended:
data ← ⍳45
a←m[;0 1 2]
b←m[;3 4 5]
c←m[;6 7 8]
d←↑a b c
d
0 1 2
9 10 11
18 19 20
27 28 29
36 37 38
3 4 5
12 13 14
21 22 23
30 31 32
39 40 41
6 7 8
15 16 17
24 25 26
33 34 35
42 43 44
The final shape will clearly be 3 (9÷⍨≢data) 3
, but we are filling one row from each layer first, then the second row from each layer, and so on. Compare this to the normal way of filling; all rows of the first layer, then all the rows of the second layer, and so on:
3 (9÷⍨≢data) 3⍴data
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14
15 16 17
18 19 20
21 22 23
24 25 26
27 28 29
30 31 32
33 34 35
36 37 38
39 40 41
42 43 44
In other words, our job is to swap the filling order of the first two axes. To do this, we list the axis lengths in the order we want them filled:
(9÷⍨≢data) 3 3⍴data
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14
15 16 17
18 19 20
21 22 23
24 25 26
27 28 29
30 31 32
33 34 35
36 37 38
39 40 41
42 43 44
Now we need to swap the first two axes. This is possible using the dyadic transpose function ⍉
which (for our use case) can be thought of as the "reorder axes" function. The left argument is an array of where you want the corresponding axis to go (first element defines the final location of the first axis and so on). While the normal indices of the axes are 0 1 2
we can swap the first two axes with 1 0 2
.
Thus 1 0 2 ⍉ (9÷⍨≢data) 3 3 ⍴ data
takes our (9÷⍨≢data) 3 3
shape and puts it into the desired shape of 3 (9÷⍨≢data) 3
.
d ≡ 1 0 2 ⍉ (9÷⍨≢data) 3 3 ⍴ data
1