Skip to main content

Vector.transpose

transpose

Group: Selections

Documentation

Swaps the rows and columns of a matrix represented by a vector of vectors.

Examples

Transpose a vector of vectors.

      matrix = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
# +---+---+---+
# | 0 | 1 | 2 |
# +---+---+---+
# | 3 | 4 | 5 |
# +---+---+---+
# | 6 | 7 | 8 |
# +---+---+---+

transposed = [[0, 3, 6], [1, 4, 7], [2, 5, 8]]
# +---+---+---+
# | 0 | 3 | 6 |
# +---+---+---+
# | 1 | 4 | 7 |
# +---+---+---+
# | 2 | 5 | 8 |
# +---+---+---+

matrix.transposed == transposed
# => True

Errors

  • If the rows (subvectors) do not all have the same length, an Illegal_Argument error is raised.