stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
12.87k stars 4.11k forks source link

shape mismatch: value array of shape (4096,) could not be broadcast to indexing result of shape (2,4096,3) #251

Closed mohala562 closed 1 year ago

mohala562 commented 2 years ago

Trying to run 04_q_learning_for_trading results in the following error:

118 print(targets.shape)
119 print(targets)

--> 120 q_values[[self.idx, actions]] = targets 122 loss = self.online_network.train_on_batch(x=states, y=q_values) 123 self.losses.append(loss)

ValueError: shape mismatch: value array of shape (4096,) could not be broadcast to indexing result of shape (2,4096,3)

Running tensorflow 2.9.2 (GPU)

ghost commented 2 years ago

Same here... have you found a solution?

dereklegenzoff commented 2 years ago

Same issue

dereklegenzoff commented 2 years ago

I changed the line in the error message to this:q_values[self.idx, actions] = targets

So far it seems to be working for me.

stefan-jansen commented 1 year ago

There have been several updates to the open AI gym since publication. Please either use the version that was current at publication (around 2020/06) or update the code accordingly.

ghostMike666 commented 1 year ago

https://www.facebook.com/mxalgrito?mibextid=ZbWKwL IP??

El sáb., 30 de julio de 2022 10:17, defc0n1 @.***> escribió:

Trying to run 04_q_learning_for_trading results in the following error:

118 print(targets.shape) 119 print(targets)

--> 120 q_values[[self.idx, actions]] = targets 122 loss = self.online_network.train_on_batch(x=states, y=q_values) 123 self.losses.append(loss)

ValueError: shape mismatch: value array of shape (4096,) could not be broadcast to indexing result of shape (2,4096,3)

Running tensorflow 2.9.2 (GPU)

— Reply to this email directly, view it on GitHub https://github.com/stefan-jansen/machine-learning-for-trading/issues/251, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATHPZIMC37NLIGZ2L2OGNUTVWVPR5ANCNFSM55DQP4LA . You are receiving this because you are subscribed to this thread.Message ID: @.***>