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
1matrix = ((0, 1), (3, 4), (6, 7))
2#Transpose matrix from 3x2 to 2x3
3
4matrix_transpose = tuple(zip(*data))
5print(data_transpose)
6
7#Output
8((0, 3, 6), (1, 4, 7), (2, 5, 8))
9
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