title: How should I fix that after I use a slice of a tensor, tensorflow optimizer will break?
body: <p>Here is a sample:</p>
  
  <pre><code>import numpy as np
  import tensorflow as tf
  from tensorflow.python.ops import rnn, rnn_cell
  
  
  if __name__ == '__main__':
  
      embs = tf.Variable(np.random.random((40,5)),dtype=tf.float32)
  
  
      X = np.array(np.array(range(1,25)).reshape(4, 6))
  
      x0 = tf.placeholder(tf.int32, [None, None])
  
      x1 = tf.nn.embedding_lookup(embs, x0)
  
  
  
      lstm = tf.nn.rnn_cell.BasicLSTMCell(5,state_is_tuple=True)   
  
  
      outputs, states = tf.nn.dynamic_rnn(lstm, x1, dtype=tf.float32,time_major = True)
  
      cost = tf.reduce_mean(outputs[:,-1,:])
  
      optimizer = tf.train.AdagradOptimizer(learning_rate=0.12).minimize(cost)
      with tf.Session() as sess:
          sess.run(tf.initialize_all_variables())
          result3, opt = sess.run([outputs, optimizer],{x0:X})
  </code></pre>
  
  <p>I use just one slice of outputs which is outputs[:,-1,:] to get a cost function. When I run the code, I got the result 
  F ./tensorflow/core/framework/tensor.h:581] Check failed: new_num_elements == NumElements() (0 vs. 20)</p>
  
  <p>How to fix this? It's just a sample. I met this problem when I implement a hierarchical LSTM in which the representations of sentences computed by a LSTM is feed into another LSTM.</p>