Creating a rotation matrix in NumPy

The two dimensional rotation matrix which rotates points in the $xy$ plane anti-clockwise through an angle $\theta$ about the origin is

$$ \mathbf{R} = \left(\begin{array}{rr}\cos\theta & -\sin\theta\\ \sin\theta & \cos\theta \end{array}\right). $$

To create a rotation matrix as a NumPy array for $\theta=30^\circ$, it is simplest to initialize it with as follows:

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]]

If, for some reason you are using NumPy's matrix subclass, then it is also possible to initialize with a string:

In [x]: theta = np.radians(30)
In [x]: c, s = np.cos(theta), np.sin(theta)
In [x]: R = np.matrix('{} {}; {} {}'.format(c, -s, s, c))
In [x]: print(R)
[[ 0.8660254 -0.5      ]
 [ 0.5        0.8660254]]

Of course, in this case it would be easier to simply pass a list of lists directly:

In [x]: R = np.matrix([[c, -s], [s, c]])