matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
]
# 方法一
# for x in range(len(matrix)):
# print (matrix[x])
# pass
hehe = [[row[i] for row in matrix] for i in range(4)]
print (hehe)
# 方法二
one = []
for x in range(4):
one.append([row[x] for row in matrix])
pass
print (one)
# 方法三
three = []
for x in range(4):
two = []
for i in matrix:
two.append(i[x])
pass
three.append(two)
pass
print (three)
python将3X4的矩阵列表转换为4X3列表
最新推荐文章于 2024-08-30 16:12:29 发布