Answers for "how to rotate a 2d matrix 90 degrees in python"

5

rotate 2d vector by angle

rotate vector (x1, y1) counterclockwise by the given angle
(angle in radians)

newX = oldX * cos(angle) - oldY * sin(angle)
newY = oldX * sin(angle) + oldY * cos(angle)
Posted by: Guest on September-13-2020
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]
Posted by: Guest on May-16-2021
1

rotate 2d array

#clockwise:
rotated = list(zip(*original[::-1]))
#counterclockwise:
rotated_ccw = list(zip(*original))[::-1]
Posted by: Guest on July-26-2021

Code answers related to "how to rotate a 2d matrix 90 degrees in python"

Browse Popular Code Answers by Language