Created
July 26, 2011 09:35
-
-
Save waynemoore/1106378 to your computer and use it in GitHub Desktop.
Transpose a matrix in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transpose(matrix): | |
num_rows = len(matrix) | |
num_cols = len(matrix[0]) | |
t_matrix = [[None for _ in range(num_rows)] for _ in range(num_cols)] | |
for y in range(num_rows): | |
for x in range(num_cols): | |
t_matrix[x][y] = matrix[y][x] | |
return t_matrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment