[Tutor] TypeError: unhashable type: 'pygame.math.Vector2'
Cravan
savageapple850 at gmail.com
Fri Jun 26 11:00:58 EDT 2020
Hi Mats,
Sorry for the late reply. Thanks for your suggestion, I realised that Q was merely giving only some values due to my class settings. However, I have no idea how to set all the coordinates as my state Space. Assuming WIDTH and HEIGHT are the width and height of my env respectively, how should I define my state space within the class itself?
Something like this (although this is wrong) :
self.stateSpace = [(i for i in range(int(WIDTH)), q for q in range(int(HEIGHT)))]
Essentially my logic is for each number in range(Width), pair it to a number in range(HEIGHT). How should I rectify the code above so as to fit my logic while also conforming to "Pythonic" laws?
Cravan
On 26/6/20, 10:43 PM, "Tutor on behalf of Mats Wichmann" <tutor-bounces+savageapple850=gmail.com at python.org on behalf of mats at wichmann.us> wrote:
On 6/26/20 8:25 AM, Cravan wrote:
> Sadly, an error pops up when I change the code.
> Here's my edited code for the class file:
> However, this error pops up:
> #######
> Traceback (most recent call last):
> File "maze.py", line 181, in <module>
> g.run()
> File "maze.py", line 53, in run
> self.update()
> File "maze.py", line 109, in update
> action_ = maxAction(Q, observationnew, possible_actions)
> File "maze.py", line 177, in maxAction
> values = np.array([Q[state,a] for a in actions])
> File "maze.py", line 177, in <listcomp>
> values = np.array([Q[state,a] for a in actions])
> KeyError: ((6, 26), 'U')
> ######
>
> Apologies for the (late) and long email here, would appreciate if someone could offer some help.
Well, again the error tells you what is happening: KeyError means you
tried to look up a key in a dictionary that is actually not present in
the dictionary.
So Q does not contain the tuple ((6, 26), 'U')
only you can tell if that's a legitimate result, or an unexpected one.
if it's *expected* that there will be some mismatches, you can do this:
try:
values = np.array([Q[state,a] for a in actions])
except KeyError:
# take appropriate action for missing key
If it's unexpected, then you have some recoding to do.
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list