Reshape: Difference between revisions

From The K Language Wiki
Content added Content deleted
("Add all appropriate categories to each verb")
("Better category ordering, add redirects to categories, fix pseudo-adverb categories")
 
Line 30: Line 30:
</pre>
</pre>


[[Category:Operator verbs]]
[[Category:Verbs]]
[[Category:Verbs]]
[[Category:Operator verbs]]
[[Category:Primitives]]
[[Category:Primitives]]

Latest revision as of 06:42, 9 July 2022

Reshape
x#y

The reshape primitive takes the elements of an array y, and fits them in a rectangular nested array shape given by x.

The array elements are repeated to fit the shape given in x, if the product of x is greater than the length of y.

 3 3#3
(3 3 3
 3 3 3
 3 3 3)

 2 4 1#("ab";56;`sdas)
((,"ab";,56;,`sdas;,"ab")
 (,56;,`sdas;,"ab";,56))

In K3, -1 can be given as a dimension to get a rectangular array. Note that if the length of the array isn't evenly divisible by the dimension, it will throw an error.

Effectively, it means "maximize this dimension with respect to the other dimension and the size of the array."

K6 and its successors allow 0N as the first or last dimension.

This can result in non-rectangular arrays, since it splits the array y to fit the constraints in x.

 3 0N#1 2 3
(,1
 ,2
 ,3)