v9.1.1
Menu

Matrix Transpose

easyFREEMatrices & TransformationsLinear AlgebraCV: Mathematical Foundations

Implement a function to compute the transpose of a given matrix, a fundamental operation in linear algebra. This task involves swapping the rows and columns of the input matrix.

The concept of a matrix transpose is crucial in various mathematical and computational contexts, as it allows for the transformation of a matrix AA into its transpose ATA^T, effectively flipping the matrix over its diagonal. If AA is an m×nm \times n matrix, then ATA^T is an n×mn \times m matrix, where the element at position (i,j)(i, j) in ATA^T is equal to the element at position (j,i)(j, i) in AA.

  1. Understand the dimensions of the input matrix AA.
  2. Create a new matrix ATA^T with swapped dimensions.
  3. Populate ATA^T with elements from AA, using the relationship (AT)ij=Aji(A^T)_{ij} = A_{ji}.
(AT)ij=Aji(A^T)_{ij} = A_{ji}

This technique is widely used in computer vision and machine learning for data transformation and matrix operations.

Example

Input
A = [[1, 2, 3],
     [4, 5, 6]]
Output
[[1, 4], [2, 5], [3, 6]]
Reasoning
  • Input: A is a 2×32 \times 3 matrix given as a list of rows: row 1 is (1,2,3)(1, 2, 3) and row 2 is (4,5,6)(4, 5, 6). So m=2m = 2 rows and n=3n = 3 columns.
  • Shape of the output: the transpose of an m×nm \times n matrix is n×mn \times m, so ATA^T is 3×23 \times 2: three rows, each holding two numbers.
  • The rule: (AT)ij=Aji(A^T)_{ij} = A_{ji}. Entry (i,j)(i, j) of the result is read from entry (j,i)(j, i) of the input, so column jj of AA becomes row jj of ATA^T.
  • Worked through: column 1 of AA is (1,4)(1, 4), column 2 is (2,5)(2, 5), column 3 is (3,6)(3, 6). These become the three rows of ATA^T, giving [[1, 4], [2, 5], [3, 6]].
  • Notice: the diagonal entries A11=1A_{11} = 1 and A22=5A_{22} = 5 stay in place. Transposing twice gives back AA, and a 1×11 \times 1 matrix such as [[1]] is its own transpose.

Constraints

  • Matrix dimensions: 1 ≤ m, n ≤ 100
  • Elements are numbers

Learn this in

More from CV: Mathematical Foundations

solution.py

Test results

Sign in to run your code against the test cases.