Split: Difference between revisions

Jump to navigation Jump to search
1,540 bytes added ,  11:28, 16 June 2020
(Created page with "{{Built-in|Split|↓}} is a monadic primitive function which reduces the rank of its argument by converting one of its axes to one level of nested a...")
 
Line 46: Line 46:
</source>
</source>


== Alternatives ==
Most dialects do not have Split. Instead, the can use [[Enclose]] (<source lang=apl inline>⊂</source>) with [[bracket axis]] or the [[Rank operator]]:
<source lang=apl>
      ↓Y
┌────┬────┬────┐
│ABCD│EFGH│IJKL│
├────┼────┼────┤
│MNOP│QRST│UVWX│
└────┴────┴────┘
      ⊂[3]Y
┌────┬────┬────┐
│ABCD│EFGH│IJKL│
├────┼────┼────┤
│MNOP│QRST│UVWX│
└────┴────┴────┘
      ⊂⍤1⊢Y
┌────┬────┬────┐
│ABCD│EFGH│IJKL│
├────┼────┼────┤
│MNOP│QRST│UVWX│
└────┴────┴────┘
</source>
It is common to split a higher-[[rank]] array into its constituent [[major cell]]s. The behaviour of Split on matrices might mislead to the belief that this is what the primitive does. However, it isn't so vectors or arrays of higher rank than 2. Instead, the solution is to use or <source lang=apl inline>⊂[1↓⍳≢⍴Y]Y</source> or <source lang=apl inline>⊂⍤¯1⊢Y</source>:
<source lang=apl>
      ⊂[1↓⍳≢⍴Y]Y
┌────┬────┐
│ABCD│MNOP│
│EFGH│QRST│
│IJKL│UVWX│
└────┴────┘
      ⊂⍤¯1⊢Y
┌────┬────┐
│ABCD│MNOP│
│EFGH│QRST│
│IJKL│UVWX│
└────┴────┘
</source>
== External links ==
== External links ==


Navigation menu