Python中的旋转矩阵模块
rotate-matrix是一个有趣的新Python模块,它允许将矩阵(二维数组)转换为顺时针旋转或逆时针旋转。它目前只有两种方法。您可以通过这些方法循环 'n' 次旋转。
安装
这个模块不是Python内置的,但可以使用以下命令安装:
pip install rotate-matrix
职能
1) clock() :顾名思义,该函数用于顺时针旋转矩阵。
Syntax: clockwise(matrix)
Parameter: Takes matrix as parameter which is of type list.
Return Value: passes the clock-wised rotated version of the matrix
例子:
Python3
import rotate_matrix
mat = [[5, 2, 6], [8, 2, 9], [3, 6, 7], [3, 6, 2]]
print(rotate_matrix.clockwise(mat))
Python3
import rotate_matrix
mat = [[5, 2, 6], [8, 2, 9], [3, 6, 7], [3, 6, 2]]
print(rotate_matrix.anti_clockwise(mat))
输出:
[(6, 9, 7, 2), (2, 2, 6, 6), (5, 8, 3, 3)]
2)anti_clock():这个模块的这个函数逆时针旋转给定的矩阵。
Syntax: anti_clockwise(matrix)
Parameter: Takes matrix as parameter which is of type list
Return Value: passes the anti-clockwise rotated version of the matrix
例子:
蟒蛇3
import rotate_matrix
mat = [[5, 2, 6], [8, 2, 9], [3, 6, 7], [3, 6, 2]]
print(rotate_matrix.anti_clockwise(mat))
输出:
[(3, 3, 8, 5), (6, 6, 2, 2), (2, 7, 9, 6)]