APL - Remove nesting and keep shape of matrix

Viewed 105

I have a 3x3 matrix of nested 3x3 matrices (which all contain numbers). How do I "de nest" all these matrices so that I end up with a 9x9 matrix.

1 Answers

Suppose this is our matrix m:

  ⎕←m←(3 3⍴⊂3 3⍴⍳9)ר(1 10 100)∘.×1 10 100
┌───────────┬──────────────┬─────────────────┐
│1 2 3      │10 20 30      │100 200 300      │
│4 5 6      │40 50 60      │400 500 600      │
│7 8 9      │70 80 90      │700 800 900      │
├───────────┼──────────────┼─────────────────┤
│10 20 30   │100 200 300   │1000 2000 3000   │
│40 50 60   │400 500 600   │4000 5000 6000   │
│70 80 90   │700 800 900   │7000 8000 9000   │
├───────────┼──────────────┼─────────────────┤
│100 200 300│1000 2000 3000│10000 20000 30000│
│400 500 600│4000 5000 6000│40000 50000 60000│
│700 800 900│7000 8000 9000│70000 80000 90000│
└───────────┴──────────────┴─────────────────┘

Then you can transform as follows:

   ⊃⍪/,/m 
  1   2   3   10   20   30   100   200   300
  4   5   6   40   50   60   400   500   600
  7   8   9   70   80   90   700   800   900
 10  20  30  100  200  300  1000  2000  3000
 40  50  60  400  500  600  4000  5000  6000
 70  80  90  700  800  900  7000  8000  9000
100 200 300 1000 2000 3000 10000 20000 30000
400 500 600 4000 5000 6000 40000 50000 60000
700 800 900 7000 8000 9000 70000 80000 90000

Basically this glues the columns row-wise together and then glues row over row - and finally discloses the resulting mat.

Related