[Tutor] TypeError: unhashable type: 'pygame.math.Vector2'
Mats Wichmann
mats at wichmann.us
Fri Jun 26 10:41:48 EDT 2020
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.
More information about the Tutor
mailing list