How to assign variables to numpy matrix
<p>I want to make a function to generate rotational matrix R. Here is my code:</p>

<pre><code>import numpy as np
def R(theta):
    a = np.cos(theta)
    b = -1*np.sin(theta)
    c = np.sin(theta)
    d = np.cos(theta)
    return np.matrix('a b; c d')
</code></pre>

<p>But it has error like this</p>

<pre><code>raise TypeError("Invalid data string supplied: " + astr)
TypeError: Invalid data string supplied: a
</code></pre>

<p>Any suggestions?</p>

<p>use <a href="https://docs.python.org/2/library/stdtypes.html#str.format" rel="nofollow">.format</a> to put the variables into string form </p>

<pre><code>return np.matrix('{} {};{} {}'.format(a,b,c,d))
</code></pre>

python numpy matrix