Transpose a Matrix

transposed_matrix(matrix)

Transpose a matrix’s rows and columns

Parameters

matrix (list of lists of int or float) – List of lists of numbers representing a matrix

Raises
  • TypeError – Argument must be a 2-dimensional list

  • TypeError – Elements nested within argument must be integers or floats

Returns

matrix – List of lists in which each inner element occupies the row that correspond’s to the column it occupied in the original matrix and the column that correspond’s to the row it occupied in the original matrix

Return type

list of lists of int or float

Notes

  • Original matrix: \(\mathbf{A} = \begin{bmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \cdots & \cdots & \cdots & \cdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{bmatrix}\)

  • Transpose of matrix: \(\mathbf{A}^T = \begin{bmatrix} a_{1,1} & a_{2,1} & \cdots & a_{m,1} \\ a_{1,2} & a_{2,2} & \cdots & a_{m,2} \\ \cdots & \cdots & \cdots & \cdots \\ a_{1,n} & a_{2,n} & \cdots & a_{m,n} \end{bmatrix}\)

  • Adjugate of a Matrix

Examples

Import transposed_matrix function from regressions library
>>> from regressions.matrices.transpose import transposed_matrix
Transpose [[1, 2, 3], [4, 5, 6]]
>>> matrix_3x2 = transposed_matrix([[1, 2, 3], [4, 5, 6]])
>>> print(matrix_3x2)
[[1, 4], [2, 5], [3, 6]]
Transpose [[2, 3], [5, 7]]
>>> matrix_2x2 = transposed_matrix([[2, 3], [5, 7]])
>>> print(matrix_2x2)
[[2, 5], [3, 7]]