numpy in python rotate 90 degrees clockwise code example
Example 1: rotate matrix 90 degrees clockwise python
#rotate 90 deg clockwise
box=[["a","b"],["c","d"],["e","f"]]
rows = len(box)
cols = len(box[0])
box2 = [[""] * rows for _ in range(cols)]
for x in range(rows):
for y in range(cols):
box2[y][rows - x - 1] = box[x][y]
Example 2: rotate 90 degrees clockwise counter python
new_matrix = [[m[j][i] for j in range(len(m))] for i in range(len(m[0])-1,-1,-1)]