title: In tensorflow, how to iterate over a sequence of inputs stored in a tensor?
body: <p>I am trying RNN on a variable length multivariate sequence classification problem.</p>
  
  <p>I have defined following function to get the output of the sequence (i.e. the output of RNN cell after the final input from sequence is fed)</p>
  
  <pre><code>def get_sequence_output(x_sequence, initial_hidden_state):
      previous_hidden_state = initial_hidden_state
      for x_single in x_sequence:
          hidden_state = gru_unit(previous_hidden_state, x_single)
          previous_hidden_state = hidden_state
      final_hidden_state = hidden_state
      return final_hidden_state
  </code></pre>
  
  <p>Here <code>x_sequence</code> is tensor of shape <code>(?, ?, 10)</code> where first ? is for batch size and second ? is for sequence length and each input element is of length 10. <code>gru</code> function takes a previous hidden state and current input and spits out next hidden state (a standard gated recurrent unit).</p>
  
  <p>I am getting an error: <code>'Tensor' object is not iterable.</code>
  How do I iterate over a Tensor in sequence manner (reading single element at a time)?</p>
  
  <p>My objective is to apply <code>gru</code> function for every input from the sequence and get the final hidden state.</p>