【发布时间】:2017-04-10 11:30:19
【问题描述】:
我只是在玩 Ipython,我收到以下错误:
In [108]: feed_dict_test = {x:x, y_true:y_true, y_true_cls:data.test.cls}
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-108-2fdafc34bea7> in <module>()
----> 1 feed_dict_test = {x:x, y_true:y_true, y_true_cls:data.test.cls}
TypeError: unhashable type: 'numpy.ndarray'
问题:
该错误清楚地说明了“TypeError”,但我如何确定三个参数中的哪个参数会产生此错误?在这种情况下 x?y_true?y_true_cls?
【问题讨论】:
-
键应该是不可变类型。
-
这些关键对象中的哪个是
numpy.ndarray的实例,或者如果有多个,则声明第一个。顺便说一句,您正在创建字典,而不是调用函数,尽管您可能想将字典作为关键字参数传递?如果是这样,您需要使用字符串作为键:{'x':x, 'y_true': y_true.....} -
谢谢回复,有3个参数,哪个参数会导致错误?,有什么办法可以通过调试弄清楚?
-
@Whoami:我认为您无法从调试消息中看出。您可以打印出对象类型以查找违规对象,也可以使用
isinstance(obj, collections.Hashable)。 -
谢谢@mhawke
标签: python python-2.7 ipython