Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting this error while running as it is. #3

Open
sampatel012 opened this issue Mar 27, 2019 · 2 comments
Open

Getting this error while running as it is. #3

sampatel012 opened this issue Mar 27, 2019 · 2 comments

Comments

@sampatel012
Copy link

[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)

@alexw92
Copy link

alexw92 commented Apr 9, 2019

You could just add another (trading) day to the time interval by modifying either the start or end date.
Then it should fit the shape.

@Chudvan
Copy link

Chudvan commented Mar 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants