python中用hcluster进行层次聚类时出错

2024-06-01 20:23:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试运行以下代码,得到一个AttributeError:“module”对象没有在最后一行中引发的属性“hcluster”。在

我在Mountain Lion中运行,我使用pip和自制程序,hcluster在PYTHONPATH=/usr/local/lib/python2.7/site-packages中。在

知道会出什么问题吗?谢谢。在

import os 
import hcluster
from numpy import *
from PIL import Image
# create a list of images
path = 'data/flickr-sunsets-small'
imlist = [os.path.join(path,f) for f in os.listdir(path) if f.endswith('.jpg')]
# extract feature vector (8 bins per color channel)
features = zeros([len(imlist), 512])
for i,f in enumerate(imlist):
    im = array(Image.open(f))
    # multi-dimensional histogram
    h,edges = histogramdd(im.reshape(-1,3),8,normed=True,range=[(0,255),(0,255),(0,255)]) 
    features[i] = h.flatten()
tree = hcluster.hcluster(features)

Tags: path对象代码infromimageimportfor