PIXELBANKv8.2.1
Menu

Matrix Transpose

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:

Step-by-step transformation using the transpose definition:

AijT=AjiA^T_{ij} = A_{ji}

Original matrix AA (2×3): A=(123456)A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}

  1. Columns become rows:

    • Column 0 [1,4][1, 4] → Row 0
    • Column 1 [2,5][2, 5] → Row 1
    • Column 2 [3,6][3, 6] → Row 2
  2. Equivalently, flip across the diagonal: AijAjiTA_{ij} \rightarrow A^T_{ji}

    • A00=1A00T=1A_{00}=1 \rightarrow A^T_{00}=1
    • A01=2A10T=2A_{01}=2 \rightarrow A^T_{10}=2
    • A02=3A20T=3A_{02}=3 \rightarrow A^T_{20}=3
    • A10=4A01T=4A_{10}=4 \rightarrow A^T_{01}=4
    • A11=5A11T=5A_{11}=5 \rightarrow A^T_{11}=5
    • A12=6A21T=6A_{12}=6 \rightarrow A^T_{21}=6
  3. Result ATA^T (3×2): AT=(142536)A^T = \begin{pmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{pmatrix}

Constraints:

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

Test Results

0/0
Run code to see test results.