有人可以在这里帮助我,我不能解决这个问题。
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'
答案 0 :(得分:0)
我不确定标签的形状。尝试以下选项:
i[0]
(就像您已经拥有的一样)i[0][0]
(如果它们是1个长度的数组)<==这是我最好的猜测float(i[0])
float(i[0][0])
如果这些都不起作用,请向我们提供mnist.train.labels.shape