How to view the source code of numpy.random.exponential?
<p>I want to see if <code>numpy.random.exponential</code> was implemented using F^{-1} (U) method, where F is the c.d.f of exponential distribution and U is uniform distribution. </p>

<p>I tried <code>numpy.source(random.exponential)</code>, but returned '<em>Not available for this object'</em>. Does it mean this function is not written in Python?</p>

<p>I also tried <code>inspect.getsource(random.exponential)</code>, but returned an error saying it's not module, function, etc.</p>

<p>numpy's sources are <a href="https://github.com/numpy/numpy" rel="nofollow">at github</a> so you can use github's <a href="https://github.com/numpy/numpy/search?utf8=%E2%9C%93&amp;q=exponential" rel="nofollow">source-search</a>.</p>

<p>As often, these parts of the library are not implemented in pure python.</p>

<p>The python-parts (in regards to your question) are <a href="https://github.com/numpy/numpy/blob/7ccf0e08917d27bc0eba34013c1822b00a66ca6d/numpy/random/mtrand/mtrand.pyx" rel="nofollow">here</a>:</p>

<p>The more relevant code-part is from <a href="https://github.com/numpy/numpy/blob/c90d7c94fd2077d0beca48fa89a423da2b0bb663/numpy/random/mtrand/distributions.c" rel="nofollow">distributions.c</a>:</p>

<pre><code>double rk_standard_exponential(rk_state *state)
{
    /* We use -log(1-U) since U is [0, 1) */
    return -log(1.0 - rk_double(state));
}

double rk_exponential(rk_state *state, double scale)
{
    return scale * rk_standard_exponential(state);
}
</code></pre>

python numpy random