# How to Transpose a Matrix in Python

To transpose a matrix A into a transpose matrix A^{T} using Python, we use the transpose() function of the library numpy

**import numpy as np
np.transpose(x)**

The argument x is the input matrix (A).

The function calculates and outputs the **transpose matrix** A^{T}.

**What is the transpose matrix?** It is a matrix in which the rows are replaced by columns. For example, the first row 1 2 3 of the matrix A is the first column of the A^{T} matrix.

**Example**

Given a 2x2 matrix created by array function of numpy.

x=np.array([[1,4,7],[2,5,8],[3,6,9]])

Calculate the transposed matrix using the function transpose(x).

y=np.transpose(x).

The transpose matrix is assigned to the variable y.

array([[1, 2, 3],

[4, 5, 6],

[7, 8, 9]])

The matrix y is the transpose matrix of x

**Report us an error or send a suggestion to improve this page**