# Understanding LSTM input shape for keras

I am learning about the LSTM network. The input needs to be 3D. So I have a CSV file which has 9999 data with one feature only. So it is only one file.

So usually it is (9999,1) then I reshape with time steps 20 steps

timesteps = 20
dim = data.shape[1]
data.reshape(len(data),timesteps,dim)


but I am getting following error

ValueError: cannot reshape array of size 9999 into shape (9999,20,1)

and the input in LSTM

model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True, activation="sigmoid"))


## 2 Answers

(9999,1) has 9999*1 elements = 9999. However, (9999,20,1) will have 9999*20*1 elements, which are not available. Break your data into a batch/sequence length of say 99. Then reshape it into (101,99,1)

RNN input shape is batch_size x sequence_length x nbr_features.

Believe you need to pre-process and setup your training data properly. You need to generate multiple training examples from the available data.

I am not sure what is your data looking like. From available info, it appears you have 9999 data points for a feature that are dependent. I would go in the below direction similar to CBOW model that builds based of conditional probabilities.

1. First identify your sequence length (say 25)
2. Generate multiple training examples from the available raw data(26th is the predictor output)
3. Proceed with training.