Reduce: Difference between revisions

Jump to navigation Jump to search
221 bytes added ,  19:11, 26 June 2023
m
m (Text replacement - "</source>" to "</syntaxhighlight>")
Tags: Mobile edit Mobile web edit
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
When applied to a [[vector]] argument, <syntaxhighlight lang=apl inline>f/x</syntaxhighlight> evaluates to the expression <syntaxhighlight lang=text inline>a f b f c f d …</syntaxhighlight> where <syntaxhighlight lang=text inline>a, b, c, d, …</syntaxhighlight> are the elements of <syntaxhighlight lang=text inline>x</syntaxhighlight>. In general, Reduce reduces one chosen [[axis]] (either implied by using the last-axis form <syntaxhighlight lang=apl inline>f/</syntaxhighlight> or first-axis <syntaxhighlight lang=apl inline>f⌿</syntaxhighlight>, or explicitly by using [[function axis]] <syntaxhighlight lang=apl inline>f/[x]</syntaxhighlight>) by evaluating each [[vector]] along the chosen axis into a [[scalar]].
When applied to a [[vector]] argument, <syntaxhighlight lang=apl inline>f/x</syntaxhighlight> evaluates to the expression <syntaxhighlight lang=text inline>a f b f c f d …</syntaxhighlight> where <syntaxhighlight lang=text inline>a, b, c, d, …</syntaxhighlight> are the elements of <syntaxhighlight lang=text inline>x</syntaxhighlight>. In general, Reduce reduces one chosen [[axis]] (either implied by using the last-axis form <syntaxhighlight lang=apl inline>f/</syntaxhighlight> or first-axis <syntaxhighlight lang=apl inline>f⌿</syntaxhighlight>, or explicitly by using [[function axis]] <syntaxhighlight lang=apl inline>f/[x]</syntaxhighlight>) by evaluating each [[vector]] along the chosen axis into a [[scalar]].


In [[nested array model]], Reduce has a strong property that the reduced axis is removed from the [[shape]] of the argument, which forces it to [[enclose]] each non-[[simple]] result in the returned array.
In [[nested array model]], Reduce has a strong property that the reduced axis is removed from the [[shape]] of the argument, which forces it to [[enclose]] each non-[[simple]] result in the returned array. It can be modeled as <syntaxhighlight lang=apl inline>f¨/</syntaxhighlight> in the leading axis model.


In [[leading axis model]], Reduce only has the first-axis form, and it reduces the [[major cell|major cells]] of the entire array, not the individual elements. It does not enclose the result either. Instead, reduction over an axis other than the first is performed via the [[Rank (operator)|Rank operator]], which [[mix|mixes]] the results into a flat array.
In [[leading axis model]], Reduce only has the first-axis form, and it reduces the [[major cell|major cells]] of the entire array, not the individual elements. It does not enclose the result either. It can be modeled as <syntaxhighlight lang=apl inline>↑∘(f⌿)∘(⊂⍤¯1)</syntaxhighlight> in the nested array model. Reduction over an axis other than the first is performed via the [[Rank (operator)|Rank operator]], which [[mix|mixes]] the results into a flat array.


== Examples ==
== Examples ==
trusted
83

edits

Navigation menu