>>> m = np.array([[1,2],[3,4]], int)
>>> m
array([[1, 2],
[3, 4]])
>>> np.rot90(m)
array([[2, 4],
[1, 3]])
>>> np.rot90(m, 2)
array([[4, 3],
[2, 1]])
>>> m = np.arange(8).reshape((2,2,2))
>>> np.rot90(m, 1, (1,2))
array([[[1, 3],
[0, 2]],
[[5, 7],
[4, 6]]])
numpy.rot90(array, k=number_rotations, axes=(0, 1))
In [x]: theta = np.radians(30)
In [x]: c, s = np.cos(theta), np.sin(theta)
In [x]: R = np.array(((c, -s), (s, c)))
Out[x]: print(R)
[[ 0.8660254 -0.5 ]
[ 0.5 0.8660254]]
def rotate(matrix):
rows = len(matrix)
cols = len(matrix[0])
res = []
for i in range(cols):
temp = []
for j in range(rows):
temp.append(matrix[j][i])
res.append(temp[::-1])
return res
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(rotate(matrix))