Reshape: Difference between revisions

Jump to navigation Jump to search
219 bytes added ,  06:53, 10 June 2020
→‎Notable uses: Point "identity matrix" to Wikipedia
Miraheze>Adám Brudzewsky
m (Text replacement - "</code>" to "</source>")
(→‎Notable uses: Point "identity matrix" to Wikipedia)
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Primitive|⍴|Reshape}} produces an array with [[shape]] given by the left argument and [[elements]] from the right argument. Elements are copied from the right argument to the result in [[ravel order]], truncating if the result has smaller [[bound]] than the right argument and repeating cyclically if it has larger bound. If the right argument is empty, [[Fill element|fills]] are used for the result elements.
{{Built-in|Reshape|⍴}} produces an array with [[shape]] given by the left argument and [[elements]] from the right argument. Elements are copied from the right argument to the result in [[ravel order]], truncating if the result has smaller [[bound]] than the right argument and repeating cyclically if it has larger bound. If the right argument is empty, [[Fill element|fills]] are used for the result elements.


== Examples ==
== Examples ==
Line 28: Line 28:
</source>
</source>


Reshape can also decrease the rank or [[bound]] of an array. One notable example is the use of an empty left argument <source lang=apl inline>[[Zilde|]]</source> to produce a [[scalar]]. The scalar is the first 0-[[cell]] of the right argument. In [[Nested array model|nested]] languages <source lang=apl inline>⍬⍴</source> is like [[First]] except that it does not remove a layer of nesting.
Reshape can also decrease the rank or [[bound]] of an array. One notable example is the use of an empty left argument [[Zilde]] (<source lang=apl inline>⍬</source>) to produce a [[scalar]]. The scalar is the first 0-[[cell]] of the right argument. In [[Nested array model|nested]] languages <source lang=apl inline>⍬⍴</source> is like [[First]] except that it does not remove a layer of nesting.
<source lang=apl>
<source lang=apl>
       9 ⍴ ∘.+⍨ 1 2 1
       9 ⍴ ∘.+⍨ 1 2 1
Line 65: Line 65:
</source>
</source>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
Here the right argument is converted to a ravel vector by ravelling and appending the [[prototype]], then [[indexing]] to produce a vector of the correct length. The indices used are the ravel indices of the result, but they are made to wrap around using [[Residue]].
Here the right argument is converted to a ravel vector by ravelling and appending the [[prototype]], then [[Bracket indexing|indexing]] to produce a vector of the correct length. The indices used are the ravel indices of the result, but they are made to wrap around using [[Residue]].


== J variant: Shape ==
== J variant: Shape ==
Line 73: Line 73:
== Notable uses ==
== Notable uses ==


Reshape can be used to produce an [[identity matrix]] by reshaping a vector which is one longer than the desired side length.
Reshape can be used to produce an [[wikipedia:identity matrix|identity matrix]] by reshaping a vector which is one longer than the desired side length.
<source lang=apl>
<source lang=apl>
       4 4 ⍴ 5↑1
       4 4 ⍴ 5↑1
Line 88: Line 88:


* [https://chat.stackexchange.com/rooms/52405/conversation/lesson-10-apl-functions-- APL Cultivation]
* [https://chat.stackexchange.com/rooms/52405/conversation/lesson-10-apl-functions-- APL Cultivation]
* [https://www.sacrideo.us/apl-a-day-4-arrays-have-elements/ Arrays have elements] (part of [https://www.sacrideo.us/tag/apl-a-day/ APL a Day])


=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Reshape.htm Dyalog]
* [http://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Reshape.htm Dyalog]
 
* [http://wiki.nars2000.org/index.php/Rho NARS2000]
* [http://wiki.nars2000.org/index.php/Rho NARS2000]
* [http://microapl.com/apl_help/ch_020_020_470.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_470.htm APLX]
* [https://code.jsoftware.com/wiki/Vocabulary/dollar#dyadic J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/dollar#dyadic J NuVoc] (as <source lang=apl inline>$</source> "Shape")  
* [https://code.jsoftware.com/wiki/Vocabulary/dollar#dyadic J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/dollar#dyadic J NuVoc] (as <source lang=apl inline>$</source> "Shape")  


{{APL built-ins}}
{{APL built-ins}}[[Category:Primitive functions]]
trusted
183

edits

Navigation menu