Reputation: 127
In order to adapt a sequence of data I want to use in a univariate LSTM and that have a "multi-step time", The simplest way is to do some padding. My initial dataset looks like this, it's a numpyarray:
X
[0.295046, 0.325147, 0.361293]
[0.249307,0.444077]
[0.570017,0.525082,0.475404,0.390616]
What I've tried so far is:
from keras.preprocessing.sequence import pad_sequences
padded_x = pad_sequences(X)
print(padded_x)
Instead of adding zeros to "complete" the dataset:
X
[0.0, 0.295046, 0.325147, 0.361293]
[0.0, 0.0, 0.249307,0.444077]
[0.570017,0.525082,0.475404,0.390616]
It just replaces all the values by 0. I don't know what I am missing...
Thanks in advance :)
Upvotes: 1
Views: 687
Reputation: 364
By default, pad_sequences
's dtype
argument is set to 'int32'
, thus resulting in the rounding of your float values to 0. You thus need to use pad_sequences(x, dtype='float32')
(or 'float64'
, as you see fit).
Upvotes: 5