Transpose: Difference between revisions

From The K Language Wiki
Content added Content deleted
("Remove lowercase again - it is in the template now")
Tag: Manual revert
("Add category")
Line 30: Line 30:
`b`e
`b`e
`c`)
`c`)

[[Category:Operator verbs]]

Revision as of 02:44, 9 July 2022

Transpose
+x
Matrix transposition

Transpose, a.k.a. flip, swaps the two leading axes of a 2+ dimensional rectangular array. Dialects differ in their treatment of atoms, lists, and ragged arrays.

 +("ab";"cd";"ef")
("ace"
 "bdf")

Atoms in otherwise rectangular arrays are extended to the full length of the corresponding dimension:

 +(`a`b`c;`d)
(`a`d
 `b`d
 `c`d)

Atoms and lists

Transposing a list in oK or ngn/k enlists it. Transposing an atom enlists twice[1]:

 +,0
,,0
 +0
,,0

K3, K4, and Kona[2] return the argument as-is.

K9 throws a rank error.

Ragged arrays

oK and ngn/k reshape shorter rows to the length of the longest row:

 +(`a`b`c;`d`e)
(`a`d
 `b`e
 `c`d)

K9 pads shorter rows with nulls:

 +(`a`b`c;`d`e)
(`a`d
 `b`e
 `c`)