title: TensorFlow dynamic_rnn regressor: ValueError dimension mismatch
body: <p>I would like to build a toy LSTM model for regression. <a href="http://mourafiq.com/2016/05/15/predicting-sequences-using-rnn-in-tensorflow.html" rel="noreferrer">This</a> nice tutorial is already too complicated for a beginner. </p>
  
  <p>Given a sequence of length <code>time_steps</code>, predict the next value. Consider <code>time_steps=3</code> and the sequences: </p>
  
  <pre><code>array([
     [[  1.],
      [  2.],
      [  3.]],
  
     [[  2.],
      [  3.],
      [  4.]],
      ...
  </code></pre>
  
  <p>the target values should be:</p>
  
  <pre><code>array([  4.,   5., ...
  </code></pre>
  
  <p>I define the following model:</p>
  
  <pre><code># Network Parameters
  time_steps = 3 
  num_neurons= 64 #(arbitrary)
  n_features = 1
  
  # tf Graph input
  x = tf.placeholder("float", [None, time_steps, n_features])
  y = tf.placeholder("float", [None, 1])
  
  # Define weights
  weights = {
     'out': tf.Variable(tf.random_normal([n_hidden, 1]))
  } 
  biases = {
     'out': tf.Variable(tf.random_normal([1]))
  }
  
  #LSTM model
  def lstm_model(X, weights, biases, learning_rate=0.01, optimizer='Adagrad'):
  
    # Prepare data shape to match `rnn` function requirements
    # Current data input shape: (batch_size, time_steps, n_features)
    # Required shape: 'time_steps' tensors list of shape (batch_size, n_features)
    # Permuting batch_size and time_steps
    input dimension: Tensor("Placeholder_:0", shape=(?, 3, 1), dtype=float32)
  
    X = tf.transpose(X, [1, 0, 2])
    transposed dimension: Tensor("transpose_41:0", shape=(3, ?, 1), dtype=float32)
  
    # Reshaping to (time_steps*batch_size, n_features)
    X = tf.reshape(X, [-1, n_features])
    reshaped dimension: Tensor("Reshape_:0", shape=(?, 1), dtype=float32)
  
    # Split to get a list of 'time_steps' tensors of shape (batch_size, n_features)
    X = tf.split(0, time_steps, X)
    splitted dimension: [&lt;tf.Tensor 'split_:0' shape=(?, 1) dtype=float32&gt;, &lt;tf.Tensor 'split_:1' shape=(?, 1) dtype=float32&gt;, &lt;tf.Tensor 'split_:2' shape=(?, 1) dtype=float32&gt;]
  
    # LSTM cell
    cell = tf.nn.rnn_cell.LSTMCell(num_neurons) #Or GRUCell(num_neurons)
  
    output, state = tf.nn.dynamic_rnn(cell=cell, inputs=X, dtype=tf.float32)
  
    output = tf.transpose(output, [1, 0, 2])
    last = tf.gather(output, int(output.get_shape()[0]) - 1)
  
  
    return tf.matmul(last, weights['out']) + biases['out']
  </code></pre>
  
  <p>We instantiating the LSTM model with <code>pred = lstm_model(x, weights, biases)</code> I get the following:</p>
  
  <pre><code>---&gt; output, state = tf.nn.dynamic_rnn(cell=cell, inputs=X, dtype=tf.float32)
  ValueError: Dimension must be 2 but is 3 for 'transpose_42' (op: 'Transpose') with input shapes: [?,1], [3]
  </code></pre>
  
  <p>1) Do you know what the problem is?</p>
  
  <p>2) Will multiplying the LSTM output by the weights yield the regression? </p>