Shape: Difference between revisions
Miraheze>Marshall mNo edit summary |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(20 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Built-in|Shape|⍴}} is a [[monadic function]] which returns the ''shape'' of its argument array, namely a [[vector]] of lengths of the array along each [[axis]]. The [[dyadic function]] using the same symbol is [[Reshape]] which produces an array of the shape specified by its left argument. | |||
An array's shape may be any vector of nonnegative integers with length less than or equal to the [[maximum rank]]. The length of an array's shape is the array's [[rank]], and the product of the shape is its [[bound]]. If the shape is [[Empty array|empty]] then the array is a [[scalar]]. | An array's shape may be any vector of nonnegative integers with length less than or equal to the [[maximum rank]]. The length of an array's shape is the array's [[rank]], and the product of the shape is its [[bound]]. If the shape is [[Empty array|empty]] then the array is a [[scalar]]. | ||
Line 7: | Line 7: | ||
== Examples == | == Examples == | ||
< | <syntaxhighlight lang="apl"> | ||
(⍬≡⍴)¨1 'A' ⍝ The shape of a scalar is the empty numeric vector ⍬ | (⍬≡⍴)¨1 'A' ⍝ The shape of a scalar is the empty numeric vector ⍬ | ||
1 1 | 1 1 | ||
Line 16: | Line 16: | ||
⍴'ABC'∘.,1 2 3 4∘.×0J1 1J2 ⍝ Two consecutive outer products result in a cuboid | ⍴'ABC'∘.,1 2 3 4∘.×0J1 1J2 ⍝ Two consecutive outer products result in a cuboid | ||
3 4 2 | 3 4 2 | ||
</ | </syntaxhighlight> | ||
{{APL | == See also == | ||
* [[Tally]] | |||
* [[Index generator]] | |||
== External links == | |||
=== Lessons === | |||
* [https://chat.stackexchange.com/rooms/52405/conversation/lesson-10-apl-functions-- APL Cultivation] | |||
* [https://www.sacrideo.us/apl-a-day-3-arrays-have-shape/ Arrays have Shape] (from [https://www.sacrideo.us/tag/apl-a-day/ APL a Day]) | |||
=== Documentation === | |||
* [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Shape.htm Dyalog] | |||
* [http://wiki.nars2000.org/index.php/Rho NARS2000] | |||
* [http://microapl.com/apl_help/ch_020_020_460.htm APLX] | |||
* [https://www.jsoftware.com/help/dictionary/d210.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/dollar J NuVoc] (as <syntaxhighlight lang=apl inline>$</syntaxhighlight> "Shape Of") | |||
* [https://mlochbaum.github.io/BQN/doc/shape.html BQN] | |||
{{APL features}} | |||
{{APL built-ins}}[[Category:Primitive functions]][[Category:Array characteristics]] |
Latest revision as of 22:05, 10 September 2022
⍴
|
Shape (⍴
) is a monadic function which returns the shape of its argument array, namely a vector of lengths of the array along each axis. The dyadic function using the same symbol is Reshape which produces an array of the shape specified by its left argument.
An array's shape may be any vector of nonnegative integers with length less than or equal to the maximum rank. The length of an array's shape is the array's rank, and the product of the shape is its bound. If the shape is empty then the array is a scalar.
An array's shape, along with the index origin, determine the possible values which can be used as an index into the array. A complete index is a vector of integers with the same length as the shape. When the index origin is subtracted from the index each element must be at least 0 and less than the corresponding element of the shape. In languages with negative indexing it may be greater than or equal to the negative of the shape rather than 0.
Examples
(⍬≡⍴)¨1 'A' ⍝ The shape of a scalar is the empty numeric vector ⍬ 1 1 ⍴'ABCDE' ⍝ The shape of a vector is a length-1 vector 5 ⍴'ABC'∘.,1 2 3 4 ⍝ The shape of the matrix result of an outer product 3 4 ⍴'ABC'∘.,1 2 3 4∘.×0J1 1J2 ⍝ Two consecutive outer products result in a cuboid 3 4 2
See also
External links
Lessons
Documentation
APL features [edit] | |
---|---|
Built-ins | Primitives (functions, operators) ∙ Quad name |
Array model | Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index (Indexing) ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype |
Data types | Number (Boolean, Complex number) ∙ Character (String) ∙ Box ∙ Namespace ∙ Function array |
Concepts and paradigms | Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity element ∙ Complex floor ∙ Array ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ Glyph ∙ Leading axis theory ∙ Major cell search ∙ First-class function |
Errors | LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR ∙ EVOLUTION ERROR |