Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created August 19, 2017 18:25
Show Gist options
  • Save ch8n/8d60f124f5d46c2ef8f5bee36269035d to your computer and use it in GitHub Desktop.
Save ch8n/8d60f124f5d46c2ef8f5bee36269035d to your computer and use it in GitHub Desktop.
Transpose of a matrix in python
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