Expand: Difference between revisions

Jump to navigation Jump to search
81 bytes added ,  22:11, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source" to "<syntaxhighlight")
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 1: Line 1:
{{Built-ins|Expand|<nowiki>\</nowiki>|⍀}} is a [[dyadic function]] or [[monadic operator]] that copies each [[element]] of the right [[argument]] a given number of times and inserts [[prototype]] elements, ordering the copies along a specified [[axis]]. Typically <syntaxhighlight lang=apl inline>\</source> is called Expand while <syntaxhighlight lang=apl inline>⍀</source> is called "Expand First" or an equivalent.
{{Built-ins|Expand|<nowiki>\</nowiki>|⍀}} is a [[dyadic function]] or [[monadic operator]] that copies each [[element]] of the right [[argument]] a given number of times and inserts [[prototype]] elements, ordering the copies along a specified [[axis]]. Typically <syntaxhighlight lang=apl inline>\</syntaxhighlight> is called Expand while <syntaxhighlight lang=apl inline>⍀</syntaxhighlight> is called "Expand First" or an equivalent.


Expand is usually associated with [[Replicate]] (<syntaxhighlight lang=apl inline>/</source>), and the two functions are related to [[Mesh]] and [[Mask]]. It shares a [[glyph]] with [[Scan]] even though Expand is naturally a [[function]] and Scan must be an [[operator]]. This incongruity is sometimes resolved by making Expand an operator itself, and sometimes by [[function-operator overloading]] allowing both syntactic elements to coexist.
Expand is usually associated with [[Replicate]] (<syntaxhighlight lang=apl inline>/</syntaxhighlight>), and the two functions are related to [[Mesh]] and [[Mask]]. It shares a [[glyph]] with [[Scan]] even though Expand is naturally a [[function]] and Scan must be an [[operator]]. This incongruity is sometimes resolved by making Expand an operator itself, and sometimes by [[function-operator overloading]] allowing both syntactic elements to coexist.


== Examples ==
== Examples ==
Line 10: Line 10:
       1 0 3 ¯2 2\'abc'
       1 0 3 ¯2 2\'abc'
a bbb  cc
a bbb  cc
</source>
</syntaxhighlight>


For [[Boolean]] left argument, Expand is the right inverse of [[Replicate]], as Expand inserts prototype elements at the exact places which Replicate will remove:
For [[Boolean]] left argument, Expand is the right inverse of [[Replicate]], as Expand inserts prototype elements at the exact places which Replicate will remove:
Line 19: Line 19:
       1 0 0 1 0 1/'a  b c'
       1 0 0 1 0 1/'a  b c'
abc
abc
</source>
</syntaxhighlight>


=== High-rank arrays ===
=== High-rank arrays ===


Expand works along a particular [[axis]], which can be specified in languages with [[function axis]] and otherwise is the first axis for <syntaxhighlight lang=apl inline>⍀</source>, and the last axis for <syntaxhighlight lang=apl inline>\</source>.
Expand works along a particular [[axis]], which can be specified in languages with [[function axis]] and otherwise is the first axis for <syntaxhighlight lang=apl inline>⍀</syntaxhighlight>, and the last axis for <syntaxhighlight lang=apl inline>\</syntaxhighlight>.


<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
Line 42: Line 42:
IJKL
IJKL
IJKL
IJKL
</source>
</syntaxhighlight>


Some implementations allow the right argument to have length 1 along the expansion axis even if other axes have lengths not equal to 1.
Some implementations allow the right argument to have length 1 along the expansion axis even if other axes have lengths not equal to 1.
Line 50: Line 50:
b  bbb
b  bbb
c  ccc
c  ccc
</source>
</syntaxhighlight>


== External Links ==
== External Links ==

Navigation menu