马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
Tmatrix = [[[]]*3]*4
print(Tmatrix)
for i in range(4):
for m in range(3):
Tmatrix[i][m] = matrix[m][i]
print(Tmatrix)
print(Tmatrix)
这样写为什么不能得到矩阵转置的结果
打印出来这样的结果....
[[[], [], []], [[], [], []], [[], [], []], [[], [], []]]
[[1, [], []], [1, [], []], [1, [], []], [1, [], []]]
[[1, 5, []], [1, 5, []], [1, 5, []], [1, 5, []]]
[[1, 5, 9], [1, 5, 9], [1, 5, 9], [1, 5, 9]]
[[2, 5, 9], [2, 5, 9], [2, 5, 9], [2, 5, 9]]
[[2, 6, 9], [2, 6, 9], [2, 6, 9], [2, 6, 9]]
[[2, 6, 10], [2, 6, 10], [2, 6, 10], [2, 6, 10]]
[[3, 6, 10], [3, 6, 10], [3, 6, 10], [3, 6, 10]]
[[3, 7, 10], [3, 7, 10], [3, 7, 10], [3, 7, 10]]
[[3, 7, 11], [3, 7, 11], [3, 7, 11], [3, 7, 11]]
[[4, 7, 11], [4, 7, 11], [4, 7, 11], [4, 7, 11]]
[[4, 8, 11], [4, 8, 11], [4, 8, 11], [4, 8, 11]]
[[4, 8, 12], [4, 8, 12], [4, 8, 12], [4, 8, 12]]
[[4, 8, 12], [4, 8, 12], [4, 8, 12], [4, 8, 12]]
|