Answers.Body: <p>An LSTM takes in a sequence of items. In Tensorflow, this takes the form of a tensor with the shape <span class="math-container">$[ batch, sequence, dim ]$</span>, where:</p>
  <ul>
  <li><span class="math-container">$batch$</span> is the size of the batch</li>
  <li><span class="math-container">$sequence$</span> is the sequence length</li>
  <li><span class="math-container">$dim$</span> is the size oft he embedding dimension.</li>
  </ul>
  <p>For example, I could have a tensor in the shape <span class="math-container">$[ 64, 100, 25 ]$</span>, and <span class="math-container">$64$</span> would be the batch size, <span class="math-container">$100$</span> would be the sequence length, and <span class="math-container">$25$</span> would be the size of the embedding dimension.</p>
  <p>To be more specific, on the sequence dimension here each element is an item in the sequence.</p>
  <p>Given the specifics of your data, each time step would be a single item in this sequence, and the features would be the embedding space, giving you a tensor in the form <span class="math-container">$[ timesteps, features ]$</span> for each input sample to your model, which would then be stacked as <span class="math-container">$[ batch_size, timesteps, features ]$</span> by e.g. Tensorflow in your data pipeline.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-26T19:37:08.537Z
Answers.Text: In regards to the data, I have data for 17 different features of data at 12 different time points for lots of different articles (about 70 thousand). What I'm curious about is how to setup the array and then reshape it. The way I currently have it looks like this:
Answers.UserDisplayName: Christopher Palmer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-26T19:40:58.013Z
Answers.Text: I can't figure out how to format it: but I will upload to original post.
Answers.UserDisplayName: Christopher Palmer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-27T18:26:26.733Z
Answers.Text: Updated answer based on your additional information.
Answers.UserDisplayName: starbeamrainbowlabs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-26T16:19:54.003Z
Answers.LastActivityDate: 2022-05-27T18:26:08.237Z
Answers.LastEditDate: 2022-05-27T18:26:08.237Z
Answers.UserDisplayName: starbeamrainbowlabs
Body: <p>I was curious if anyone had any advice on how to reshape data for a recurrent neural network. What I've been doing is array.reshape(len(X_train), # of points in time, # of features)</p>
  <p>And then in the array, the X axis represents the features, and for each item, there are entries corresponding to the number of points in time (and a column with id so I know what the original id is). So if the time series has 12 points, each sample will have 12 entries in a row in the array.</p>
  <p>Am I reshaping correctly, and if not, how can I reshape correctly?</p>
  <p><strong>Edit</strong>
  The array initially looks like this:
  <a href="https://i.sstatic.net/ZHrkU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZHrkU.png" alt="enter image description here" /></a></p>
  <p>This is a pandas array which I convert to numpy by using values.astype(float). The article, and timestep column are just for reference. I am using the command array.reshape(-1, 12, 17)
  The -1 is the length of the array, 12 is the timesteps (or number of entries in y axis for each article), and the 17 is the number of features at each time step. I am then feeding that data to a recurrent neural network.</p>
  
Tags: <neural-networks><deep-learning><recurrent-neural-networks><data-preprocessing>
Title: How should you reshape data before feeding it to LSTM layers?
UserDisplayName: Christopher Palmer
ThreadText: # How should you reshape data before feeding it to LSTM layers?
  
  (Asked by: username_0 on 2022-05-26)
  
  I was curious if anyone had any advice on how to reshape data for a recurrent neural network. What I've been doing is array.reshape(len(X\_train), # of points in time, # of features)
  
  And then in the array, the X axis represents the features, and for each item, there are entries corresponding to the number of points in time (and a column with id so I know what the original id is). So if the time series has 12 points, each sample will have 12 entries in a row in the array.
  
  Am I reshaping correctly, and if not, how can I reshape correctly?
  
  **Edit**
  The array initially looks like this:
  [![enter image description here](https://i.sstatic.net/ZHrkU.png)](https://i.sstatic.net/ZHrkU.png)
  
  This is a pandas array which I convert to numpy by using values.astype(float). The article, and timestep column are just for reference. I am using the command array.reshape(-1, 12, 17)
  The -1 is the length of the array, 12 is the timesteps (or number of entries in y axis for each article), and the 17 is the number of features at each time step. I am then feeding that data to a recurrent neural network.
  
  **Tags:** neural-networks, deep-learning, recurrent-neural-networks, data-preprocessing
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-05-26. Score: 2
  
  An LSTM takes in a sequence of items. In Tensorflow, this takes the form of a tensor with the shape $[ batch, sequence, dim ]$, where:
  
  * $batch$ is the size of the batch
  * $sequence$ is the sequence length
  * $dim$ is the size oft he embedding dimension.
  
  For example, I could have a tensor in the shape $[ 64, 100, 25 ]$, and $64$ would be the batch size, $100$ would be the sequence length, and $25$ would be the size of the embedding dimension.
  
  To be more specific, on the sequence dimension here each element is an item in the sequence.
  
  Given the specifics of your data, each time step would be a single item in this sequence, and the features would be the embedding space, giving you a tensor in the form $[ timesteps, features ]$ for each input sample to your model, which would then be stacked as $[ batch\_size, timesteps, features ]$ by e.g. Tensorflow in your data pipeline.
  
  > **Comments:**
  > **username_0**: In regards to the data, I have data for 17 different features of data at 12 different time points for lots of different articles (about 70 thousand). What I'm curious about is how to setup the array and then reshape it. The way I currently have it looks like this:  
  > **username_0**: I can't figure out how to format it: but I will upload to original post.  
  > **username_1**: Updated answer based on your additional information.  
  
  ---
  
  