Difference between logarithm in numpy and theano.tensor
<p>What is the difference between numpy.log and theano.tensor.log?
Do they perform the same?</p>

<p>It is likely that <code>numpy.log</code> will be faster. You can compare them both on your CPU and your data.</p>

<pre><code>import theano
import theano.tensor as T
import numpy as 

x = T.vector('x')
theano_log = theano.function([x], T.log(x))

a = np.random.rand(1000).astype(np.float32)  # test data
assert np.allclose(theano_log(a), np.log(a)) # optional correctness check
</code></pre>

<p>Then measure with:</p>

<pre><code>In [6]: %timeit np.log(a)
100000 loops, best of 3: 7.89 Âµs per loop

In [7]: %timeit theano_log(a)
10000 loops, best of 3: 44.1 Âµs per loop
</code></pre>

<p>So for a vector of size 1000 <code>numpy</code> is about 5 times faster. This results might vary if you switch to run the calculations in a GPU which you can do with <code>theano</code> and not with <code>numpy</code>.</p>

<p>The main difference is the way you use each library. In theano if you want to do several operations to an array (ex: log->square->mean) you would declare first a computation graph and then evaluate the whole graph at once which might result in some optimizations. With <code>numpy</code> you would evaluate each intermediate step, creating many intermediate variables on the process that can in some cases be avoided in <code>theano</code>.</p>

python numpy theano