>>> def rotate_matrix( k: List[List[int]]):
"""
For example, if I have:
m = [[1,2,3],
[2,3,3],
[5,4,3]]
rotate_matrix(m) should give me [[3,3,3],[2,3,4],[1,2,5]].
"""
编辑:最好没有 numpy。
原文由 user10634718 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是纯 python 中的一行逆时针矩阵旋转(即,没有 numpy):
如果你想在一个函数中这样做,那么
无论哪种方式,结果
是
另外,如果你想要通常的转置,那么简单的一行纯 python 版本是