' numpy.ndarray'对象没有属性' iteritems'

时间:2017-02-19 00:25:33

标签: python

我想获得784维度的原始数字直方图。 这是我的代码:

Traceback (most recent call last):
  File "HW3.py", line 56, in <module>
    distances = computeDistances(datasets.DigitData.X)
  File "HW3.py", line 39, in computeDistances
    dist.append( exampleDistance(data[n],data[m])  / sqrt(D))
  File "HW3.py", line 23, in exampleDistance
    for i,v1 in x1.iteritems():
AttributeError: 'numpy.ndarray' object has no attribute 'iteritems'

但是出了点问题:

class DigitData:
    Xall,Yall = loadDigitData('data/1vs2.all')
    N,D = Xall.shape
    N0 = int(float(N) * 0.5)
    X = Xall[0:N0,:]
    Y = Yall[0:N0]
    Xte = Xall[N0:,:]
    Yte = Yall[N0:]

此外,这里是数字数据集:

--my_column--
"{431}"
"{431,33}"
"{431,60}"
"{431,28}"
"{431,1}"
"{431,226}"
"{431,38}"
"{431,226,229}"
"{431,226,227}"
"{431,226,235}"
"{431,226,239}"
"{431,226,241}"

然后我该如何解决?作为一个蟒蛇初学者,我对绘图非常困惑。

1 个答案:

答案 0 :(得分:0)

我建议您阅读此earlier post,如果您仍然没有找到您的答案评论。我希望这会有所帮助。