python矩阵的转置和逆转实例
如下所示:
# 矩阵的转置 def transpose(list1): return [list(row) for row in zip(*list1)] list1 = [[1, 4], [2, 5], [3, 6]] print(transpose(list1)) # [[1, 2, 3], [4, 5, 6]]
矩阵转置
用zip将一系列可迭代对象中的元素打包为元组,之后将这些元组放置在列表中,两步加起来等价于行列转置。
# 矩阵逆转 def invert(list1): return [row[::-1] for row in list1] list1 = [[1, 4], [2, 5], [3, 6]] print(invert(list1)) # [[4, 1], [5, 2], [6, 3]]
矩阵逆转
取出每行的元素,逆序索引遍历 = 左右翻转。
相关推荐
guangmingsky 2020-06-05
sdwylry 2020-02-20
sasac 2020-09-25
huangjie0 2020-09-25
cloudking000 2020-09-11
xiaoxiaokeke 2020-07-28
mingyunxiaohai 2020-07-28
honghao0 2020-07-27
风吹夏天 2020-07-26
夕加加 2020-07-20
CallmeZhe 2020-06-29
zhoujiyu 2020-06-28
清风徐来水波不兴 2020-06-16
Happyunlimited 2020-06-15
wanff0 2020-06-14
cuiguanjun 2020-06-13
啸林 2020-06-12
jiayuqicz 2020-06-09
章鱼之家 2020-06-08