title: Concatenate identity matrix to each vector
body: <p>I want to modify my input by adding several different suffixes to the input vectors. For example, if the (single) input is <code>[1, 5, 9, 3]</code> I want to create three vectors (stored as matrix) like this:</p>
  
  <pre><code>[[1, 5, 9, 3, 1, 0, 0],
   [1, 5, 9, 3, 0, 1, 0],
   [1, 5, 9, 3, 0, 0, 1]]
  </code></pre>
  
  <p>Of course, this is just one observation so the input to the model is <code>(None, 4)</code> in this case. The simple way is to prepare the input data somewhere else (numpy most probably) and adjust the shape of input accordingly. That I can do but I would prefer doing it inside TensorFlow/Keras.</p>
  
  <p>I have isolated the problem into this code:</p>
  
  <pre><code>import keras.backend as K
  from keras import Input, Model
  from keras.layers import Lambda
  
  
  def build_model(dim_input: int, dim_eye: int):
      input = Input((dim_input,))
      concat = Lambda(lambda x: concat_eye(x, dim_input, dim_eye))(input)
      return Model(inputs=[input], outputs=[concat])
  
  
  def concat_eye(x, dim_input, dim_eye):
      x = K.reshape(x, (-1, 1, dim_input))
      x = K.repeat_elements(x, dim_eye, axis=1)
      eye = K.expand_dims(K.eye(dim_eye), axis=0)
      eye = K.tile(eye, (-1, 1, 1))
      out = K.concatenate([x, eye], axis=2)
      return out
  
  
  def main():
      import numpy as np
  
      n = 100
      dim_input = 20
      dim_eye = 3
  
      model = build_model(dim_input, dim_eye)
      model.compile(optimizer='sgd', loss='mean_squared_error')
  
      x_train = np.zeros((n, dim_input))
      y_train = np.zeros((n, dim_eye, dim_eye + dim_input))
      model.fit(x_train, y_train)
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>The problem seems to be in the <code>-1</code> in <code>shape</code> argument in <code>tile</code> function. I tried to replace it with <code>1</code> and <code>None</code>. Each has its own error:</p>
  
  <ul>
  <li><p><code>-1</code>: error during <code>model.fit</code></p>
  
  <pre><code>tensorflow.python.framework.errors_impl.InvalidArgumentError: Expected multiples[0] &gt;= 0, but got -1
  </code></pre></li>
  <li><p><code>1</code>: error duting <code>model.fit</code></p>
  
  <pre><code>tensorflow.python.framework.errors_impl.InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [32,3,20] vs. shape[1] = [1,3,3]
  </code></pre></li>
  <li><p><code>None</code>: error during <code>build_model</code>:</p>
  
  <pre><code>Failed to convert object of type &lt;class 'tuple'&gt; to Tensor. Contents: (None, 1, 1). Consider casting elements to a supported type.
  </code></pre></li>
  </ul>