Python中的矩阵转置
theArray = [['a','b','c'],['d','e','f'],['g','h','i']]
newArray = [['a','d','g'],['b','e','h'],['c', 'f', 'i']]
def matrixTranspose(anArray): transposed = [None]*len(anArray[0]) for t in range(len(anArray)): for tt in range(len(anArray[t])): transposed[t] = [None]*len(anArray) transposed[t][tt] = anArray[tt][t] print transposed
Qyouu
相关分类