Generate a two dimensional array of complex numbers
<p>I want to generate a two dimensional array of a given size containing complex numbers like in this example:</p>

<pre><code>&gt;&gt;&gt; generate_array((2, 3))
array([[ 0.+0.j,  1.+0.j,  2.+0.j],
       [ 0.+1.j,  1.+1.j,  2.+1.j]])
</code></pre>

<p>Here is a way to achieve this<br>
using <code>np.indices()</code> engaged with <code>np.vectorize()</code>:</p>

<pre><code>def generate_array(dim):
    X, Y = np.indices(dim)
    return np.array(np.vectorize(complex)(X, Y))

ar = generate_array((2, 3))
print(ar)
</code></pre>

<p>Output:</p>

<pre><code>[[ 0.+0.j  0.+1.j  0.+2.j]
 [ 1.+0.j  1.+1.j  1.+2.j]]
</code></pre>

python numpy