title: Reshaping arrays in Time-Series RNN Beginners Block
body: <p>New to python and deep learning. I was trying to build an RNN with some data and I don't know where am I going wrong.</p>
  
  <p>This is my code:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  %matplotlib inline
  
  
  
  raw = pd.read_excel('Online Retail.xlsx',index_col='InvoiceDate')
  sales = raw.drop(['InvoiceNo','StockCode','Country','Description'],axis=1)
  sales.head()
  sales.index = pd.to_datetime(sales.index)
  sales.info()
  
  train_set = sales.head(50000)
  test_set = sales.tail(41909)
  
  from sklearn.preprocessing import MinMaxScaler
  scaler = MinMaxScaler()
  
  
  training =  np.nan_to_num(train_set)
  testing = np.nan_to_num(test_set)
  
  train_scaled = scaler.fit_transform(training)
  test_scaled = scaler.fit_transform(testing)
  
  
  def next_batch(training_data,batch_size,steps):
    rand_start = np.random.randint(0,len(training_data)-steps)
    y_batch = 
    np.array(training_data[rand_start:rand_start+steps+1].reshape(26,steps+1))
    return 
    y_batch[:,:-1].reshape(-1,steps,1),y_batch[:,1:].reshape(-1,steps,1)
  
    import tensorflow as tf
  
  
    num_inputs = 1
    num_time_steps = 10
    num_neurons = 100
    num_outputs = 1
    learning_rate = 0.03
    num_train_iterations = 4000
    batch_size = 1
  
    X = tf.placeholder(tf.float32,[None,num_time_steps,num_inputs])
    y = tf.placeholder(tf.float32,[None,num_time_steps,num_outputs])
  
    cell = tf.contrib.rnn.OutputProjectionWrapper(
   tf.contrib.rnn.BasicLSTMCell(num_units=num_neurons,activation=tf.nn.relu),output_size=num_outputs) 
  
   outputs, states = tf.nn.dynamic_rnn(cell, X, dtype=tf.float32)
  
   loss = tf.reduce_mean(tf.square(outputs - y)) # MSE
   optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
   train = optimizer.minimize(loss)
  
   init = tf.global_variables_initializer()
   saver = tf.train.Saver()
   with tf.Session(config=tf.ConfigProto()) as sess:
       sess.run(init)
  
       for iteration in range(num_train_iterations):
  
          X_batch, y_batch = next_batch(train_scaled,batch_size,num_time_steps)
          sess.run(train, feed_dict={X: X_batch, y: y_batch})
  
          if iteration % 100 == 0:
  
              mse = loss.eval(feed_dict={X: X_batch, y: y_batch})
              print(iteration, "\tMSE:", mse)
  
      # Save Model for Later
      saver.save(sess, "./ex_time_series_model")
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-36-f2f7c66a33df&gt; in &lt;module&gt;()
        4         for iteration in range(num_train_iterations):
        5 
  ----&gt; 6             X_batch, y_batch = next_batch(train_scaled,batch_size,num_time_steps)
        7             sess.run(train, feed_dict={X: X_batch, y: y_batch})
        8 
  
  &lt;ipython-input-26-f673a469c67d&gt; in next_batch(training_data, batch_size, steps)
        1 def next_batch(training_data,batch_size,steps):
        2     rand_start = np.random.randint(0,len(training_data)-steps)
  ----&gt; 3     y_batch = np.array(training_data[rand_start:rand_start+steps+1].reshape(26,steps+1))
        4     return y_batch[:,:-1].reshape(-1,steps,1),y_batch[:,1:].reshape(-1,steps,1)
  
  ValueError: cannot reshape array of size 33 into shape (26,11)
  
  In [ ]:
  </code></pre>