LSTM Output Structure import tensorflow as tf
import numpy as np
from tensorflow.python.ops import rnn_cell, rnn

data = np.random.randint(0, 10, size = (1000, 18))
batch_size = 10
chunk_size = 6
n_timesteps = 3
rnn_size = 128

x = tf.placeholder('float', [batch_size, n_timesteps, chunk_size])
y = tf.placeholder('float')

def neural_network(x):
    x = tf.transpose(x, [1,0,2])
    x = tf.reshape(x, (-1, chunk_size))
    x = tf.split(x, n_timesteps)

    lstm = rnn_cell.BasicLSTMCell(rnn_size)
    outputs, states = rnn.static_rnn(lstm, x, dtype = tf.float32)
    print("Number of outputs: ", len(outputs))
    print("Last output: ", outputs[-1])
    print("LSTM Cell: ", lstm)
    print("Input Data: ", x[0])
    return outputs[-1]

prediction = neural_network(x)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    p = sess.run(prediction, feed_dict = {x:data[:batch_size].reshape((batch_size, n_timesteps, chunk_size))})

Running the code gives me the following output:
('Number of outputs: ', 3)
('Last output: ', <tf.Tensor 'rnn/rnn/basic_lstm_cell/mul_8:0' shape=(10, 128) dtype=float32>)
('LSTM Cell: ', <tensorflow.python.ops.rnn_cell_impl.BasicLSTMCell object at 0x7fc57f5ec390>)
('Input Data: ', <tf.Tensor 'split:0' shape=(10, 6) dtype=float32>)

It makes sense that the number of outputs is 3 because the number of timesteps is 3. What I don't understand is how the last output of the LSTM has a shape of (batch_size, rnn_size). 
 A: First of all, tf.nn.static_rnn documentation states:

Returns:
A pair (outputs, state) where:
  
  
*
  
*outputs is a length T list of outputs (one for each input), or a
  nested tuple of such elements. 
  
*state is the final state
  

Like you already said, in your example, there are T=3 cells, i.e., outputs is a list of 3 outputs of each BasicLSTMCell. 
Now, let's have a look at what tf.contrib.rnn.BasicLSTMCell outputs:

Returns:
A pair containing:
  
  
*
  
*Output: A 2-D tensor with shape [batch_size x self.output_size]. 
  
*New state: Either a single 2-D tensor, or a tuple of tensors matching the arity and shapes of state.
  

If you look at the classical LSTM picture, it makes perfect sense:

When you pass a single sequence $x_t$, the output of each cell is the vector $h_t$, which has the shape (rnn_size,). Naturally, feeding the mini-batch of length batch_size to the LSTM would produce the mini-batch of outputs, each of (rnn_size,) shape. Hence the result shape (batch_size, rnn_size).
