4,493
edits
m (Text replacement - "<source" to "<syntaxhighlight") Tags: Mobile edit Mobile web edit |
m (Text replacement - "</source>" to "</syntaxhighlight>") Tags: Mobile edit Mobile web edit |
||
Line 19: | Line 19: | ||
(,×/⍴x) ≡ ⍴,x ⍝ Or the product of the original shape | (,×/⍴x) ≡ ⍴,x ⍝ Or the product of the original shape | ||
1 | 1 | ||
</ | </syntaxhighlight> | ||
Ravelling a [[scalar]] yields a [[singleton]] [[vector]]. | Ravelling a [[scalar]] yields a [[singleton]] [[vector]]. | ||
Line 29: | Line 29: | ||
⍴,3 ⍝ It's now a vector | ⍴,3 ⍝ It's now a vector | ||
1 | 1 | ||
</ | </syntaxhighlight> | ||
[[String]] notation cannot produce a single-character string since it produces a [[scalar]] character instead. Using Ravel on a list of characters in quotes ensures it will be a [[vector]] of characters. | [[String]] notation cannot produce a single-character string since it produces a [[scalar]] character instead. Using Ravel on a list of characters in quotes ensures it will be a [[vector]] of characters. | ||
Line 37: | Line 37: | ||
≢⍴ ,'a' ⍝ String | ≢⍴ ,'a' ⍝ String | ||
1 | 1 | ||
</ | </syntaxhighlight> | ||
[[Function axis|Axis specification]] may accept either a [[vector]] of two or more adjacent [[axis]] [[Index|indices]], or a single non-integer value. If multiple axes are given, they are merged into one axis whose length is the product of their lengths. If only one value is given, a new axis of length 1 is inserted in the indicated "gap" between axes. | [[Function axis|Axis specification]] may accept either a [[vector]] of two or more adjacent [[axis]] [[Index|indices]], or a single non-integer value. If multiple axes are given, they are merged into one axis whose length is the product of their lengths. If only one value is given, a new axis of length 1 is inserted in the indicated "gap" between axes. | ||
Line 45: | Line 45: | ||
⍴ ,[2.5] 5 4 3 2⍴0 | ⍴ ,[2.5] 5 4 3 2⍴0 | ||
5 4 1 3 2 | 5 4 1 3 2 | ||
</ | </syntaxhighlight> | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]]}} | ||
== Description == | == Description == | ||
The ravel of an array <syntaxhighlight lang=apl inline>A</ | The ravel of an array <syntaxhighlight lang=apl inline>A</syntaxhighlight> has shape <syntaxhighlight lang=apl inline>,×/⍴A</syntaxhighlight> and shares elements with <syntaxhighlight lang=apl inline>A</syntaxhighlight>. Thus Ravel may be modelled as a [[Reshape|reshaping]] function <syntaxhighlight lang=apl inline>{(×/⍴⍵)⍴⍵}</syntaxhighlight>. The [[element]] with [[index]] [[vector]] <syntaxhighlight lang=apl inline>I</syntaxhighlight> is moved to index <syntaxhighlight lang=apl inline>(⍴A)⊥I</syntaxhighlight> in [[index origin]] 0, or <syntaxhighlight lang=apl inline>⎕IO+(⍴A)⊥I-⎕IO</syntaxhighlight> in arbitrary index origin. | ||
As with any reshaping, the result of Ravel has the same [[prototype]] as the argument. | As with any reshaping, the result of Ravel has the same [[prototype]] as the argument. |