In linear algebra, the **transpose** of a matrix **A** is another matrix **A**^{T} (also written **A**′, **A**^{tr},^{t}**A** or **A**^{t}) created by any one of the following equivalent actions:

- reflect
**A**over its main diagonal (which runs from top-left to bottom-right) to obtain**A**^{T} - write the rows of
**A**as the columns of**A**^{T} - write the columns of
**A**as the rows of**A**^{T}

Formally, the *i* th row, *j* th column element of **A**^{T} is the *j* th row, *i* th column element of **A**:

If **A** is an *m* × *n* matrix then **A**^{T} is an *n* × *m* matrix.

Code

public static int[,] Transpose(int[,] matrix) { int row = matrix.GetLength(0); int column = matrix.GetLength(1); Console.WriteLine("Input Matrix"); PrintMatrix(matrix); int[,] transpose = new int[column, row]; for (int rowCounter = 0; rowCounter < row; rowCounter++) { for (int columnCounter = 0; columnCounter < column; columnCounter++) { transpose[columnCounter, rowCounter] =

matrix[rowCounter, columnCounter]; } } Console.WriteLine("Transpose"); PrintMatrix(transpose); return transpose; }

Filed under:
Array

Leave a comment