在python里用loop做矩阵的置换
发布网友
发布时间:2022-04-19 01:40
我来回答
共3个回答
热心网友
时间:2022-04-19 03:09
In [1]: a = ([1,2,3], [4,5,6])
In [2]: b = tuple(zip(*a))
In [3]: b
Out[3]: ((1, 4), (2, 5), (3, 6))
In [4]: tuple(zip(*b))
Out[4]: ((1, 2, 3), (4, 5, 6))
热心网友
时间:2022-04-19 04:27
>>> a = ([1,2,3],[4,5,6])
>>> b = zip(*a)
>>> b
[(1, 4), (2, 5), (3, 6)]
>>> c = zip(*b)
>>> c
[(1, 2, 3), (4, 5, 6)]
>>>
热心网友
时间:2022-04-19 06:02
def transpose(matrix):
M = len(matrix)
N = len(matrix[0])
t = []
for i in range(0, N):
r = []
for j in range(0, M):
r.append(matrix[j][i])
t.append(r)
return t
追问谢谢