1
我有一個模塊在Python寫輸入矩陣,看起來像:矩陣轉置(蟒蛇3)
matrix = []
loop = True
while loop:
line = input()
if not line: #the way it works is that you enter value separated by a space and enter a blank line to finish inputing the matrix
loop = False
values = line.split()
row = [int(value) for value in values]
matrix.append(row)
print('\n'.join([' '.join(map(str, row)) for row in matrix]))
最後一行就是打印的矩陣這樣
1 2 3
4 5 6
我希望能夠轉置矩陣另一個模塊,我想這至今:
def transpose_matrix(matrix):
zip(*matrix)
return matrix
但它實際上犯規WO rk它對實際矩陣沒有任何影響,矩陣保持不變,我沒有得到它。
謝謝!