Skip to content

Structuring of Arrays

Primitive functions that restructure arrays:

symbol monadic dyadic
reshape
, ravel laminate and catenate
table catenate first
⌽⍟ reverse rotate
transpose
mix take
split drop
enlist
enclose partitioned enclose
nest partition

Examples

      ⊢m←2 2⍴1 2 3 4                   ⍝ reshape
1 2
3 4

      2 2 4⍴'ABCDEFGHIJKLMNOP'
ABCD
EFGH

IJKL
MNOP
      ,m                               ⍝ ravel
1 2 3 4
      1 2 3,4                          ⍝ catenate
1 2 3 4
      1⌽1 2 3 4                        ⍝ rotate
2 3 4 1
      ⌽m                               ⍝ reverse
2 1
4 3
      ⊖m                               ⍝ reverse first
3 4
1 2
      ⍉m                               ⍝ transpose
1 3
2 4
      ↑(1 2 3)(4)                      ⍝ mix
1 2 3
4 0 0
      ↓2 4⍴'COWSHENS'                  ⍝ split
┌────┬────┐
│COWS│HENS│
└────┴────┘
      [ 1 2 3 ⋄ (4 5) 6 (7 8 9)]
┌───┬─┬─────┐
│1  │2│3    │
├───┼─┼─────┤
│4 5│6│7 8 9│
└───┴─┴─────┘
      ∊[ 1 2 3 ⋄ (4 5) 6 (7 8 9)]      ⍝ enlist
1 2 3 4 5 6 7 8 9
      ≢⎕←⊂1 2 3 4                      ⍝ enclose
┌───────┐
│1 2 3 4│
└───────┘
1
      2 0 1 3 0 2 0 1⊂'abcdefg'        ⍝ partitioned enclose
┌┬──┬─┬┬┬──┬┬──┬┐
││ab│c│││de││fg││
└┴──┴─┴┴┴──┴┴──┴┘
      1 1 2 2 2⊆1 2 3 4 5              ⍝ partition
┌───┬─────┐
│1 2│3 4 5│
└───┴─────┘