# Transpose of a Matrix in Python

A transpose of a matrix is obtained by interchanging all its rows into columns or columns into rows. It is denoted by \(\displaystyle {{A}^{t}}\) or \(\displaystyle {{A}^{‘}}\). For example,

IfÂ \(\displaystyle A=\left[ {\begin{array}{*{20}{c}} 1 & 2 & 3 \\ 4 & 3 & 5 \\ 2 & 6 & 2 \end{array}} \right]\,\) thenÂ \(\displaystyle A=\left[ {\begin{array}{*{20}{c}} 1 & 4 & 2 \\ 2 & 3 & 6 \\ 3 & 5 & 2 \end{array}} \right]\)

In transpose of a matrix, the values of matrix are not changing, only their positions are changing. When we take the transpose of a same vector two times, we again obtain the initial vector. Further, A m x n matrix transposed will be a n x m matrix as all the rows of a matrix turn into columns and vice versa.

Letâ€™s start a practical example of taking a transpose of a matrix in pythonâ€¦

First, we import the relevant libraries in Jupyter Notebook. We use NumPy**,** a library for the python programming that allows us to work with multidimensional arrays and matrices along with a large collection of high-level mathematical functions to operate on these arrays as shown below,

## Transpose of a Matrix

Letâ€™s see more examples of transpose of a matrix â€¦

In above examples, you can see that, only rows of two matrices B and C are changed into columns and columns into rows.

Letâ€™s see an example of taking transpose of a scalar and a vector.

It transpires from above examples that when we take a transpose of a scalar or vector, we obtain the same result because in python one dimensional array do not get transposed.

However, if we intend to get the transpose of a vector then we will reshape it into 4 x 1 matrix or 2-dimensional array, letâ€™s do it practically,

**Further reading**

- Matrix Addition and Subtraction in Python
- Dot Product of Two Matrices in Python
- Linear Algebra for Data Science