<p dir="auto">Matlab has a function called complexrandn which generates a 2D complex matrix from uniform distribution. I need to use 2D complex number random matrix sometimes. Here is the code which I made to deal with it. It would be great if I could have it built in. You may like to also scale up to N dimensions as per the inputs given. Also, my code takes RandomState as an argument whereas you may like to do it like np.random.RandomState(513).conplexrandn()</p>
<p dir="auto">Thanks for your services to open source</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
def complexrandn(M,N,randomGen = np.random):
    data = randomGen.randn(M,N,2).view(complex)
    return np.array([ np.array([ complex(data[i][j]) for j in range(N) ]) for i in range(M) ] )

randomGen = p.random.RandomState(513)
x = complexrandn(2,2,randomGen) # To use a particular random stream
y = complexrandn(2,2) # To use global random stream
# You may like to do it as randomGen.complexrandn (It would be better for all)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">def</span> <span class="pl-en">complexrandn</span>(<span class="pl-v">M</span>,<span class="pl-v">N</span>,<span class="pl-s1">randomGen</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>):
    <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">randomGen</span>.<span class="pl-en">randn</span>(<span class="pl-v">M</span>,<span class="pl-v">N</span>,<span class="pl-c1">2</span>).<span class="pl-en">view</span>(<span class="pl-s1">complex</span>)
    <span class="pl-k">return</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([ <span class="pl-s1">np</span>.<span class="pl-en">array</span>([ <span class="pl-en">complex</span>(<span class="pl-s1">data</span>[<span class="pl-s1">i</span>][<span class="pl-s1">j</span>]) <span class="pl-k">for</span> <span class="pl-s1">j</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-v">N</span>) ]) <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-v">M</span>) ] )

<span class="pl-s1">randomGen</span> <span class="pl-c1">=</span> <span class="pl-s1">p</span>.<span class="pl-s1">random</span>.<span class="pl-v">RandomState</span>(<span class="pl-c1">513</span>)
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-en">complexrandn</span>(<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-s1">randomGen</span>) <span class="pl-c"># To use a particular random stream</span>
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-en">complexrandn</span>(<span class="pl-c1">2</span>,<span class="pl-c1">2</span>) <span class="pl-c"># To use global random stream</span>
<span class="pl-c"># You may like to do it as randomGen.complexrandn (It would be better for all)</span></pre></div>
<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">1.16.3 3.6.7 (default, Oct 22 2018, 11:32:17)<br>
[GCC 8.2.0]</p>
<p dir="auto"><strong>What's the need?</strong><br>
random.multivariate_normal works great for but is limited to sampling real vectors. Today, if ones would like to generate from complex multivariate distribution from (mu, Omega), sampling would need these steps:</p>
<ol dir="auto">
<li>get Omega^1/2 by cholesky decomposition (or svd)</li>
<li>generate a serie z of random complex gaussian numbers whose elements are in Nc(0, 1)</li>
<li>get the sample mu + Omega^1/2 * z</li>
</ol>
<p dir="auto"><strong>Featuring it? How?</strong><br>
Would it be possible to extend today's function to complex numbers? I imagine two possibilites<br>
for implementing that:</p>
<ol dir="auto">
<li>in the case where the given input mean array and covariance matrix are complex type, get the dtype of mu and Omega, and infer the right distribution to sample</li>
<li>add a kwarg or dtype in function to enforce if resulting sampling is real or complex</li>
</ol>