Name and function for the following matrix operation in R : <p>I am trying to reproduce this [50 x 50] matrix generated with Python as:</p>

<pre><code>n = 50                                         
a = np.linspace(-5, 5, n).reshape(-1,1)
b = a
np.sum(a**2, 1).reshape(-1, 1) + np.sum(b**2, 1)
</code></pre>

<p>using R. The problem is that the result is some sort of matrix, which cannot be reproduced through:</p>

<pre><code>n = 50     
a = seq(-5, 5, length.out = n)
b = a
a^2 + b^2
</code></pre>

<p>which generates a vector.</p>

<p>I am not familiar with the object names in Python, but I see that <code>np.sum(a**2, 1).reshape(-1, 1)</code> produces what looks like a [50 x 1] column vector:</p>

<pre><code>array([[  2.50000000e+01],
       [  2.30008330e+01],
       ...
       [  2.10849646e+01],
       [  2.30008330e+01],
       [  2.50000000e+01]])
</code></pre>

<p>while <code>np.sum(b**2, 1)</code>:</p>

<pre><code>array([  2.50000000e+01,   2.30008330e+01,   2.10849646e+01,
         1.92523948e+01,   1.75031237e+01,   1.58371512e+01,
         ...
         1.27551020e+01,   1.42544773e+01,   1.58371512e+01,
         1.75031237e+01,   1.92523948e+01,   2.10849646e+01,
         2.30008330e+01,   2.50000000e+01])
</code></pre>

<p>looks like the transposed of that same vector. So we have an operation of the form [50 x 1] * [1 x 50] = [50 x 50].</p>

<p>What is the generic name of this operation? And how can I reproduce it in R?</p>
