# Rotate a vector by angle (degree, radian) in NumPy

How to rotate the 2D vector by degree in Python:

from math import cos, sin

import numpy as np

rot = np.array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])

v = np.array([1, 0])
w = np.array([3, 4])

v2 = np.dot(rot, v)
w2 = np.dot(rot, w)

print(v2)  # [0.8660254 0.5      ]
print(w2)  # [0.59807621 4.96410162]


rot is a rotation matrix.

$\rm{Rot} = \left( \begin{array}{ccc} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array} \right)$

## The image of rotation by 30 degrees

from math import cos, sin

import numpy as np
from matplotlib import pyplot

rot = np.array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])

v = np.array([1, 0])
w = np.array([3, 4])

v2 = np.dot(rot, v)
w2 = np.dot(rot, w)

print(v2)  # [0.8660254 0.5      ]
print(w2)  # [0.59807621 4.96410162]

axes = pyplot.gca()

axes.set_xlim([-6, 6])
axes.set_ylim([-6, 6])

c1 = pyplot.Circle((0, 0), 1, fill=False)
c2 = pyplot.Circle((0, 0), 5, fill=False)

axes.set_aspect(1)