attentioned-dual-stage-stock-prediction
attentioned-dual-stage-stock-prediction copied to clipboard
use item() to fix IndexError
Greetings,
I got the following error when i tried to run the code:
Traceback (most recent call last):
File "trainer.py", line 142, in <module>
trainer.train_minibatch(num_epochs, batch_size, interval)
File "trainer.py", line 51, in train_minibatch
loss_sum += loss.data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
And as it described using item() fixed the problem and it's training now
Best Regards, Ahmed
The code in this pull request is similar to what I needed in order to make the code work.