How to add each element in two vectors with Theano?
<p>I would like to know how to add each element in two vectors with Theano?</p>

<p>Assume that we have two vector <em>vector_1</em> and <em>vecotr_2</em>, and we would like to construct a matrix <em>A</em>, where</p>

<blockquote>
  <p><em>A[i][j]</em> = <em>vector_1[i]</em> + <em>vecotr_2[j]</em></p>
</blockquote>

<p>I know that in numpy we can use list comprehension. But i would like to use Theano obtain the result with less time. It seems that Theano.scan() can do this job, but i really don't know how to deal with it.</p>

<p>You can make use of broadcasting. Here is an example in NumPy, you can do the same in Theano:</p>

<pre><code>&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; x1 = np.array([1,1,9]).reshape((3,1))
&gt;&gt;&gt; x2 = np.array([0,3,4]).reshape((1,3))
&gt;&gt;&gt; np.add(x1, x2)
array([[ 1,  4,  5],
       [ 1,  4,  5],
       [ 9, 12, 13]])
</code></pre>

python theano theano.scan