1>>> a = np.array([[1, 2], [3, 4]])
2>>> a
3array([[1, 2],
4 [3, 4]])
5>>> a.transpose()
6array([[1, 3],
7 [2, 4]])
8>>> a.transpose((1, 0))
9array([[1, 3],
10 [2, 4]])
11>>> a.transpose(1, 0)
12array([[1, 3],
13 [2, 4]])
14
1import numpy as np
2
3A = [1, 2, 3, 4]
4np.array(A).T # .T is used to transpose matrix
1def transpose(matrix):
2 rows = len(matrix)
3 columns = len(matrix[0])
4
5 matrix_T = []
6 for j in range(columns):
7 row = []
8 for i in range(rows):
9 row.append(matrix[i][j])
10 matrix_T.append(row)
11
12 return matrix_T
13