0

I want to make a sliding window for LSTM. For this I have:

x_train=[[]]
y_train = []

for i in range(10, len(train_data)):
  x_train.append(train_data[i-10:i])
  y_train.append(train_data[i,0])

The shape of train_data is (2730, 2), so I suppose x_train will be (2721, 10, 2).
After the loop x_train and y_train are lists of numpy arrays.
In tutorials it's enough to apply np.asarray or np.array to change it to numpy array. In my case it changes shape to (2721, ) and that's not really what I expected.
Probably, it's better to use numpy arrays and not lists.
But I wonder why in tutorials the way I do works and it doesn't for me. Maybe there is a small error or something in the code?

P.S. Sorry, I found an error by myself. It was x_train=[[]], but it should be x_train=[].

6
  • maybe this answer your question? Commented Mar 11, 2021 at 14:51
  • thank you, it's solved. Commented Mar 11, 2021 at 14:55
  • 1
    Does this answer your question? How to convert list of numpy arrays into single numpy array? Commented Mar 11, 2021 at 14:55
  • @Chris,its same link Commented Mar 11, 2021 at 14:58
  • @matanh yeah it's auto filled when I voted to close the question as duplicated, if you have the rep to vote to close that's probably better than posting the link directly. Commented Mar 11, 2021 at 14:58

1 Answer 1

0

Thank you for your comments. Actually in that situation it was a good solution to concatenate numpy arrays. Here I made an error creating a wrong type of list, so the fix is rather obvious, just to replace x_train=[[]] by x_train=[].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.