python - TypeError: unhashable type: 'numpy.ndarray' mnist
问题描述
有人可以在这里帮助我,我无法解决这个问题。
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=False)
dataWithLabels = zip(mnist.train.labels, mnist.train.images)
digitDict = {}
for i in range(0,10):
digitDict[i] = []
for i in dataWithLabels:
digitDict[i[0]].append(i[1])
for i in range(0,10):
digitDict[i] = np.matrix(digitDict[i])
print("Digit {0} matrix shape: {1}".format(i,digitDict[i].shape))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-34-05052c24d917> in <module>()
15 # Assign a list of image vectors to each corresponding digit class index.
16 for i in dataWithLabels:
---> 17 digitDict[i[0]].append(i[1])
18
19 # Convert the lists into numpy matricies. (could be done above, but I claim ignorace)
TypeError: unhashable type: 'numpy.ndarray'
解决方案
我不确定标签的形状。尝试以下选项:
i[0]
(就像你已经拥有的一样)i[0][0]
(如果它们是长度为 1 的数组)<== 这是我最好的猜测float(i[0])
float(i[0][0])
如果这些都不起作用,请提供给我们mnist.train.labels.shape
推荐阅读
- javascript - 未捕获的类型错误:无法读取 null 的属性“firstElementChild”
- python - Python Paramiko,尝试连接时关闭属性错误“Nonetype”
- c# - 将用户控件中的事件绑定到父窗口路由事件 - C# XAML
- sql-server - 由于创建了额外的列而导致的 Python 拆分问题
- reactjs - 如何从内联小图像中禁用 ReactDOMServer.renderToStaticMarkup?
- c# - 如何使用 C# 代码创建挂起的迁移 sql server 脚本
- dart - BottomAppBar 中缺少停靠的 FloatingActionButton 的缺口
- eclipse - 我可以以编程方式指定 Eclipse RCP 编辑器部件的大小吗?
- asp.net-web-api2 - 可选参数的空值 ASP.NET Web API
- inno-setup - Inno Setup:如何使用用户输入有条件地执行代码