title: How to pairwise combine a row and a column of features to a matrix of features in keras?
body: <p>In keras, using the functional API, I have two independent layers (tensors). The first one is a row vector of feature lists and the other one is a column vector of feature lists. For simplicity, suppose they are created like this:</p>
  
  <pre><code>rows = 5
  cols = 10
  features = 2
  
  row = Input((1, cols, features))
  col = Input((rows, 1, features))
  </code></pre>
  
  <p>Now I want to "merge" these two layers in a way that the result is a matrix with 5 rows and 10 columns (basically doing a <code>5x1</code> by <code>1x10</code> matrix multiplication) where each entry of that matrix is a concatenated feature list of every possible combination of the row and column vector.
  In other words, I'm looking for some <code>MergeLayer</code> that will combine my <code>row</code> and <code>col</code> layers to a <code>matrix</code> layer of shape <code>(rows, cols, 2*features)</code>:</p>
  
  <pre><code>matrix = MergeLayer()([row, col]) # output_shape of matrix shall be (rows, cols, 2*features)
  </code></pre>
  
  <p>Example for <code>cols = rows = 2</code>:</p>
  
  <pre><code>row = [[[1,2]], [[3,4]]]
  col = [[[5,6],
          [7,8]]]
  
  matrix = [[[1,2,5,6], [3,4,5,6]],
            [[1,2,7,8], [3,4,7,8]]]
  </code></pre>
  
  <p>I'm assuming that the solution (if possible at all) will somehow leverage the the <code>Dot</code> layer and maybe some <code>Reshape</code> and/or <code>Permute</code>, but I can't figure it out.</p>