# Difference between revisions of "Axis"

Miraheze>Adám Brudzewsky m (Text replacement - "</code>" to "</source>") |
Miraheze>Adám Brudzewsky |
||

Line 10: | Line 10: | ||

The choice to give leading axes lower indices and trailing axes higher indices is related to the choice to put lower-order places at higher indices in the base representation functions [[Decode]] and [[Encode]]. This is known in the wider programming world as a [https://en.wikipedia.org/wiki/Endianness big-endian] order. Because the base representation and axis ordering are in alignment, [[selection]] of an single element from an array satisfies the clean identity <source lang=apl inline>i⌷A ←→ ((⍴A)⊥i)⌷,A</source>. If base representation used the opposite order, both of Decode's arguments would need to be reversed. | The choice to give leading axes lower indices and trailing axes higher indices is related to the choice to put lower-order places at higher indices in the base representation functions [[Decode]] and [[Encode]]. This is known in the wider programming world as a [https://en.wikipedia.org/wiki/Endianness big-endian] order. Because the base representation and axis ordering are in alignment, [[selection]] of an single element from an array satisfies the clean identity <source lang=apl inline>i⌷A ←→ ((⍴A)⊥i)⌷,A</source>. If base representation used the opposite order, both of Decode's arguments would need to be reversed. | ||

+ | |||

+ | {{APL programming language}} |

## Revision as of 19:53, 30 October 2019

In the APL array model, an axis is one dimension along which the elements of an array are organized. The rank of an array is the number of axes it has, and the shape is the list of their lengths. The index of a single element of an array is composed of a one index along each axis. An index along one axis is a single number; in this sense, axes are one-dimensional.

## Axis ordering

The axes of an array are numbered in the same way as elements of the shape. Axis numbering is subject to index origin. Axis indices are used to specify function axis and in some functions such as dyadic Transpose.

Axis indices are the first of two ordering properties which axes are subject to. The ravel order defines another hierarchy of axes: moving one step along the lowest axis in this hierarchy moves by one step in the ravel, while moving along a higher axis moves by the product of the lengths of all lower axes. These orderings do not have an obvious natural correspondence, but APLs universally equate earlier indices with higher axes. Thus we refer to higher axes in the hierarchy as "leading axes" and lower axes as "trailing axes". Outside of APL this choice is known as row major order.

Use of the Rank operator allows a programmer to control which axes are used without referring to them explicitly (for example, by index). Rank, and more generally the leading axis theory, uses the ravel order axis hierarchy directly without requiring another ordering to be imposed on axes. Despite this, the choice to make a positive operand to Rank specify a cell rank, while a negative operand specifies a frame length, weakly suggests an ordering that places trailing axes first and leading axes last—the opposite of the index ordering.

The choice to give leading axes lower indices and trailing axes higher indices is related to the choice to put lower-order places at higher indices in the base representation functions Decode and Encode. This is known in the wider programming world as a big-endian order. Because the base representation and axis ordering are in alignment, selection of an single element from an array satisfies the clean identity `i⌷A ←→ ((⍴A)⊥i)⌷,A`

. If base representation used the opposite order, both of Decode's arguments would need to be reversed.