Random numbers- only length-1 arrays can be converted to Python scalars
<pre><code>from math import sin, cos, pi
import numpy as np
N=10

a=np.random.randint(0, 360+1, N)
print (a)

theta=a*pi/180
print(theta)

x=[cos(theta)]
print(x)
y=[sin(theta)]
print(y)
</code></pre>

<hr>

<pre><code>TypeError                                 Traceback (most recent call last)
&lt;ipython-input-47-632b45c2aba1&gt; in &lt;module&gt;()
      9 theta=a*pi/180
     10 print(theta)
---&gt; 11 x=[cos(theta)]
     12 print(x)
     13 y=[sin(theta)]

TypeError: only length-1 arrays can be converted to Python scalars
</code></pre>

<p>Try using <code>np.cos(theta)</code> instead of <code>cos(theta)</code>. Same goes for <code>sin</code>.</p>

<p>Only NumPy functions can be applied both to scalars and arrays. The regular <code>cos()</code> and <code>sin()</code> instead expect only scalar arguments, and fail in the example, as you try to apply them on a NumPy array of size 10.</p>

<p>NumPy <code>cos</code> documentation: <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.cos.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.cos.html</a>
<code>cos</code> documentation: <a href="https://docs.python.org/2/library/math.html" rel="nofollow">https://docs.python.org/2/library/math.html</a></p>

python arrays numpy random polar-coordinates