Last active
September 5, 2017 11:31
-
-
Save volf52/f634fbdbfbf211e45c2515ae340d95c0 to your computer and use it in GitHub Desktop.
Transpose a matrix (2D array) 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): | |
return [[row[i] for row in matrix] for i in range(len(matrix[0]))] | |
# this one is a bit slower | |
def t2(matrix): | |
return map(list, zip(*matrix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment