The Keras LSTM layer has the following call argument doc :
Call arguments:
inputs: A 3D tensor with shape [batch, timesteps, feature].
The Matrix that you gave is of 2D shape (5, 5)
i.e. 5 rows and 5 columns.
Since you are using LSTM, let me give you an example with text data:
Cat sat on the dog
The above sentence has 5 words, each word can be vectorized into 5 dimensions (Word Embedding).
This makes your sentence become a tensor of 2D shape of (5,5)
Now you can have multiple sentences.
- Dog sat on the cat
- Cat ate the dog food
- Dog ate the cat food
So now you have total 4 sentences which is your batch. Each of these 4 sentence will have a tensor of (5,5)
since all have 5 words in them and you are encoding each word with 5 dimensions.
Thus your whole dataset has the shape:
[batch, timesteps, feature] == [4, 5, 5]
You can now feed this 3D tensor into your LSTM layer.
In case you just want to feed that 2D matrix you will have to expand the dimension using np.expand_dims() to become (1, 5, 5)
3D shape
list2 = np.expand_dim(list2, axis=0)
print(list2)
print(list2.shape)
[[[0 1 2 3 4]
[1 2 3 4 5]
[2 3 4 5 6]
[3 4 5 6 7]
[4 5 6 7 8]]]
(1, 5, 5)
Also refer to Understanding Keras LSTMs