Search code examples
pythontensorflowkeraslstm

how to reshape array to predict with LSTM


I made an LSTM model based on this tutorial where the model input batch shape is:

print(config["layers"][0]["config"]["batch_input_shape"])

returns:

(None, 1, 96)

Can someone give me a tip on how change my testing data to this array shape to match the model input batch size?

testday = read_csv('./data.csv', index_col=[0], parse_dates=True)
testday_scaled = scaler.fit_transform(testday.values)

print(testday_scaled.shape)

returns

(96, 1)

Solution

  • IIUC, You need to use numpy.swapaxes and then add None to the first dimension.

    import numpy as np
    testday_scaled = np.swapaxes(testday_scaled, 0, 1)
    testday_scaled = testday_scaled[None, ...]