Vector: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
In the APL [[array model]], a '''vector''' is an array with [[rank]] 1. Its shape is thus a [[singleton]], whose only element is equal to the array's [[bound]]. Outside of APL, such one-dimensional data might also be called a "list" or "array".
In the APL [[array model]], a '''vector''' is an array with [[rank]] 1. Its shape is thus a [[singleton]], whose only element is equal to the array's [[bound]]. Outside of APL, such one-dimensional data might also be called a "list" or "array".


Results of the [[Shape]] and [[Ravel]] functions are always vectors. Because every array is defined by its shape and ravel (<source lang=apl inline>A ≡ (⍴A)⍴,A</source>), the multidimensional APL [[array model]] can be built up from only an understanding of vectors.
Results of the [[Shape]] and [[Ravel]] functions are always vectors. Because every array is defined by its shape and ravel (<syntaxhighlight lang=apl inline>A ≡ (⍴A)⍴,A</syntaxhighlight>), the multidimensional APL [[array model]] can be built up from only an understanding of vectors.


A [[simple array]] can also represented using [[nested]] vectors, where each vector represents a [[cell]] and the elements of a vector are the [[major cell]]s of that cell. However, nested vectors are not equivalent to arrays because they are more permissive: the elements of a vector need not all have the same length, and may even be a mix of vectors and [[simple scalar]]s. Nonetheless, some APL-derived languages like [[K]] discard the multidimensional array model in favor of nested vectors.
A [[simple array]] can also represented using [[nested]] vectors, where each vector represents a [[cell]] and the elements of a vector are the [[major cell]]s of that cell. However, nested vectors are not equivalent to arrays because they are more permissive: the elements of a vector need not all have the same length, and may even be a mix of vectors and [[simple scalar]]s. Nonetheless, some APL-derived languages like [[K]] discard the multidimensional array model in favor of nested vectors.
Line 9: Line 9:
A vector differs from a [[set]] or [[multiset]] in that its elements are ordered (additionally, sets do not allow multiple copies of an element while vectors do). Sets and multisets can be represented by vectors, but because there are multiple representations these encodings may not be compared faithfully using [[Match]].
A vector differs from a [[set]] or [[multiset]] in that its elements are ordered (additionally, sets do not allow multiple copies of an element while vectors do). Sets and multisets can be represented by vectors, but because there are multiple representations these encodings may not be compared faithfully using [[Match]].


Many APL functions, such as [[Reverse]], are most naturally defined on vectors. They may be extended to general arrays by applying along a specific axis (see [[function axis]]) or, in [[leading axis theory]], by treating an array as a vector of its [[major cell]]s (an array can be converted to such a vector using <source lang=apl inline>⊂⍤¯1</source>). For many operations, such as [[scalar function]] [[reduction]]s and most [[structural function]]s, these extensions are equivalent. Reversing along the first axis of an array by reversing each vector [[subarray]] along that axis is identical to reversing the array's major cells. For more complicated operations like general reductions they are different: a reduction along the first axis (<source lang=apl inline>⌿</source> in most APLs) passes individual array elements to its operand while reducing the major cells (<source lang=j inline>/</source> in [[J]]) passes entire cells, and performs fewer function calls.
Many APL functions, such as [[Reverse]], are most naturally defined on vectors. They may be extended to general arrays by applying along a specific axis (see [[function axis]]) or, in [[leading axis theory]], by treating an array as a vector of its [[major cell]]s (an array can be converted to such a vector using <syntaxhighlight lang=apl inline>⊂⍤¯1</syntaxhighlight>). For many operations, such as [[scalar function]] [[reduction]]s and most [[structural function]]s, these extensions are equivalent. Reversing along the first axis of an array by reversing each vector [[subarray]] along that axis is identical to reversing the array's major cells. For more complicated operations like general reductions they are different: a reduction along the first axis (<syntaxhighlight lang=apl inline>⌿</syntaxhighlight> in most APLs) passes individual array elements to its operand while reducing the major cells (<syntaxhighlight lang=j inline>/</syntaxhighlight> in [[J]]) passes entire cells, and performs fewer function calls.
{{APL features}}
{{APL features}}[[Category:Kinds of array]]

Latest revision as of 10:32, 11 September 2022

This article is about one-dimensional arrays. For the periodical, see Vector journal.

In the APL array model, a vector is an array with rank 1. Its shape is thus a singleton, whose only element is equal to the array's bound. Outside of APL, such one-dimensional data might also be called a "list" or "array".

Results of the Shape and Ravel functions are always vectors. Because every array is defined by its shape and ravel (A ≡ (⍴A)⍴,A), the multidimensional APL array model can be built up from only an understanding of vectors.

A simple array can also represented using nested vectors, where each vector represents a cell and the elements of a vector are the major cells of that cell. However, nested vectors are not equivalent to arrays because they are more permissive: the elements of a vector need not all have the same length, and may even be a mix of vectors and simple scalars. Nonetheless, some APL-derived languages like K discard the multidimensional array model in favor of nested vectors.

A vector differs from a set or multiset in that its elements are ordered (additionally, sets do not allow multiple copies of an element while vectors do). Sets and multisets can be represented by vectors, but because there are multiple representations these encodings may not be compared faithfully using Match.

Many APL functions, such as Reverse, are most naturally defined on vectors. They may be extended to general arrays by applying along a specific axis (see function axis) or, in leading axis theory, by treating an array as a vector of its major cells (an array can be converted to such a vector using ⊂⍤¯1). For many operations, such as scalar function reductions and most structural functions, these extensions are equivalent. Reversing along the first axis of an array by reversing each vector subarray along that axis is identical to reversing the array's major cells. For more complicated operations like general reductions they are different: a reduction along the first axis ( in most APLs) passes individual array elements to its operand while reducing the major cells (/ in J) passes entire cells, and performs fewer function calls.

APL features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell searchFirst-class function
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR