Created
August 19, 2017 18:25
-
-
Save ch8n/8d60f124f5d46c2ef8f5bee36269035d to your computer and use it in GitHub Desktop.
Transpose of 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 trans(m): | |
numRows = len(m) | |
numCols = len(m[0]) | |
tMatrix = [[0 for x in range(numRows)] for y in range(numCols)] | |
for i in range(0,numCols): | |
for j in range(0,numRows): | |
tMatrix[i][j] = m[j][i] | |
return tMatrix | |
print(trans([[1,3,5],[2,4,6]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment