Python TypeError: 'float' object has no attribute '__getitem__' -
anybody knows how solve problem? i'm studying collective intelligence now, , compared example when made code. it's getting error this:
traceback (most recent call last): file "<pyshell#8>", line 1, in <module> clust=clusters.hcluster(data) file "d:\kuliah\smt1\phyton class\contoh coding\coding-collective intelligence\myself_maulida\bab3-documentclustering\clusters.py", line 78, in hcluster in range(len(clust[0].vec))] typeerror: 'float' object has no attribute '__getitem__'
here code, can help? thank you.
def hcluster(rows,distance=pearson): distances={} currentclustid=-1 #clusters rows clust=[bicluster(rows[i],id=i) in range(len(rows))] while len(clust)>1: lowestpair=(0.1) closest=distance(clust[0].vec,clust[1].vec) #loop through every pair looking smallest distance in range(len(clust)): j in range(i+1,len(clust)): #distance cache of distance calculations if(clust[i].id,clust[j].id) not in distances: distances[(clust[i].id,clust[j].id)]=distance(clust[i].vec,clust[j].vec) d=distances[(clust[i].id,clust[j].id)] if d<closest: closest=d lowestpair=(i,j) #calculate average of 2 cluster mergevec=[ (clust[lowestpair[0]].vec[i]+clust[lowestpair[1]].vec[i])/2.0 in range(len(clust[0].vec))] #create new cluster newcluster=bicluster(mergevec,left=clust[lowestpair[0]], right=clust[lowestpair[1]], distance=closest,id=currentclustid) #cluster ids weren't in original set negative currentclustid-=1 del clust[lowestpair[1]] del clust[lowestpair[0]] clust.append(newcluster) return clust[0]
lowestpair=(0.1)
that's period, not comma. lowestpair
float, rather tuple. (while looks error comes clust[0]
, python tracebacks aren't @ pointing out physical line of logical line error comes from.)
Comments
Post a Comment