You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem occurs because you are trying to change the shape of the stock array to (1, 10, 1), but the size of the stock array is 9, which is incompatible with the required shape (1, 10, 1).
Your code uses a stock array that contains stock price data. In this particular case, it is initialized as follows:
data = pdr.get_data_yahoo("AAPL", "2017-12-19", "2018-01-03")
stock = data["Adj Close"]
The error occurs because the stock price data retrieved by pdr.get_data_yahoo only contains 9 elements, and your code is trying to change the shape of this array to (1, 10, 1), which requires 10 elements.
To fix this, you can change the size of the data obtained from Yahoo Finance so that the number of data is 10. For example, you can change the date range to get more data.
Here's an example fix:
data = pdr.get_data_yahoo("AAPL", "2017-12-18", "2018-01-04") # Change the date range
stock = data["Adj Close"]
Now stock contains 10 days worth of stock price data and the code should work without errors.
[100%**] 1 of 1 downloaded
Traceback (most recent call last):
File "LSTM_model.py", line 37, in
X_predict = np.array(stock).reshape((1, 10, 1)) / 200
ValueError: cannot reshape array of size 9 into shape (1,10,1)
The text was updated successfully, but these errors were encountered: