ValueError Error when checking input expected lstm_1_input to have 3 dimensions, but got array with shape 10, 1
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
This Keras error appears when an LSTM layer receives a 2D array but expects a 3D tensor. The fix is not just "reshape until it works"; you need to understand what each LSTM dimension means so the model reflects the real structure of your sequence data.
Why LSTM Input Must Be 3D
An LSTM expects input shaped as:
(samples, timesteps, features)
Those dimensions mean:
- '
samples: how many sequences you pass to the model' - '
timesteps: how many positions each sequence contains' - '
features: how many values exist at each timestep'
If your array has shape (10, 1), Keras sees only two dimensions:
- 10 rows
- 1 column
That is not enough for an LSTM because the layer needs to know both sequence length and feature count.
A Minimal Working Example
Suppose each training example is a sequence of five numbers, and each timestep has one feature. Ten training samples then need shape (10, 5, 1).
This works because:
- there are 10 samples
- each sample has 5 timesteps
- each timestep has 1 feature
Why Shape (10, 1) Usually Fails
If you pass:
then Keras cannot infer whether:
- you have 10 sequences of length 1 with a missing feature dimension
- one sequence of length 10 with one feature
- some other incorrect reshaping entirely
That ambiguity is why the LSTM rejects the input.
How to Reshape Correctly
The right reshape depends on the meaning of your data.
Case 1: each row is one sequence with one feature per timestep
Case 2: each timestep contains multiple features
For example, if you have 10 samples, 4 timesteps, and 3 features per timestep:
Output:
The model input definition must match:
Choosing the Correct Model Input Shape
The Input shape for an LSTM excludes the batch dimension. So if the actual training tensor is (10, 5, 1), the model should declare:
Do not write (10, 5, 1) there. The leading dimension is the number of samples in the current batch and should stay flexible.
Also note that many tutorials use:
That is valid, but an explicit Input layer is often clearer.
Common Pitfalls
The most common mistake is confusing rows with timesteps. A 2D array may look correct in NumPy, but an LSTM does not treat it like a normal tabular model.
Another mistake is forcing a reshape that changes the meaning of the data. If you reshape (10, 1) into (1, 10, 1), the code may run, but you have changed ten samples into one sequence. That is only correct if the data truly represents one sequence.
A third issue is mixing LSTM models with tabular features that have no temporal order. If your dataset is ordinary independent rows, a dense network may be more appropriate than an LSTM.
Finally, remember that the target array y must also match the model output. Fixing the LSTM input shape does not help if the labels are incorrectly shaped for the chosen loss function.
Summary
- LSTMs require 3D input shaped as
(samples, timesteps, features). - An array with shape
(10, 1)is only 2D, so Keras rejects it. - Reshape based on the real meaning of your sequence data, not by guesswork.
- Define the model input as
(timesteps, features), excluding the batch dimension. - If your data is not sequential, consider using a non-LSTM model instead.

