title: How to control output-size from LSTM cell in tensorflow
body: <p>I have tried to construct a simple example of using an LSTM RNN via Tensorflow to predict time-series values of some target series, given known input time-series.</p>
  
  <p><a href="https://i.stack.imgur.com/GfkAu.png" rel="nofollow noreferrer">Link to example problem</a></p>
  
  <p>I am trying to</p>
  
  <p><a href="https://i.stack.imgur.com/RG9To.gif" rel="nofollow noreferrer">what I try to accomplish formally</a></p>
  
  <p>In essence I think the output of the cell A and the following matrix mult should function as :</p>
  
  <pre><code>X = np.zeros([40,2,1])
  A = np.zeros([40,1,2])
  b = np.arange(0,2)
  
  X = tf.convert_to_tensor(X)
  A = tf.convert_to_tensor(A)
  b = tf.convert_to_tensor(b)
  
  Y = tf.matmul(X,A)+b
  </code></pre>
  
  <p>The tensorflow code is setup to view output sizes, and not with functional tf.graph/session:</p>
  
  <pre><code>import numpy as np
  import tkinter
  import matplotlib.pyplot as plt
  import tensorflow as tf
  n=40
  x = np.linspace(0,10,n)
  y1 = np.sin(x)
  y2 = np.cos(x)
  
  x1=np.random.normal(0,y1**2,n)
  x2=np.random.normal(0,y2**2,n)
  
  y1=(y1**2&gt;0.4)*1
  y2=(y2**2&gt;0.4)*1
  
  ys = np.vstack((y1,y2))
  xs = np.vstack((x1,x2))
  
  def plot_results_multiple(xs, ys):
      fig = plt.figure(facecolor='white')
      ax = fig.add_subplot(111)
      for i, data in enumerate(xs):
          plt.plot(data, label='x'+str(i))
          plt.legend()
      for i, data in enumerate(ys):
          plt.plot(data, label='y'+str(i))
          plt.legend()
      plt.show()
  
  plot_results_multiple(xs,ys)
  
  xs = xs.T
  ys = ys.T
  
  print("Shape of arrays " +str(xs.shape) + " " +str(ys.shape))
  
  
  batch_size = 1
  lstm_size = 1
  nseries = 2
  time_steps = 40
  nclasses = 2
  
  lstm = tf.contrib.rnn.BasicLSTMCell(lstm_size,state_is_tuple=True)
  stacked_lstm = tf.contrib.rnn.MultiRNNCell([lstm] * 2, state_is_tuple=True)
  
  state = lstm.zero_state(batch_size, tf.float32)
  inputs = tf.unstack(xs, num=40, axis=0)
  
  outputs = []
  
  with tf.variable_scope("RNN"):
      for timestep in range(time_steps):
          if timestep &gt; 0: tf.get_variable_scope().reuse_variables()
          output, state = lstm(tf.cast(tf.reshape(inputs[timestep],[1,nseries]),tf.float32), state)
          print(tf.convert_to_tensor(output).get_shape())
          outputs.append(output)
  
  print(tf.convert_to_tensor(outputs).get_shape())
  output = tf.reshape(tf.concat(outputs, 1), [-1, lstm_size])
  softmax_w = tf.get_variable(
      "softmax_w", [time_steps, 1,nclasses],tf.float32)# dtype=
  print(softmax_w.get_shape())
  softmax_b = tf.get_variable("softmax_b", [nseries], dtype=tf.float32)
  print(softmax_b.get_shape())
  logits = tf.matmul(output, softmax_w) + softmax_b
  
  print(logits.get_shape())
  </code></pre>
  
  <p>I think that the problem I'm having is figuring out how to modify the RNN LSTM cell, as it is currently outputting a 1x1 tensor, from a 2x1 input, where I'm expecting a 2x1 out put. Any help is very much appreciated.</p>