❶ 【python】請問ttk.Treeview增加樹狀結構時,values是什麼作用

遇到不知道的函數先help(tree.insert)查看函數幫助,或用dir(tree.insert)查看函數或類的成員。

❷ python中 怎麼把輸入是一個有包含關系的列表 生成樹形數據結構

fatherid就是節點在list中的下標,childreni[]放所有子節點在list中的下標,總之就是用下標來標記

❸ python怎麼做聚類樹狀圖

#-*-coding:utf-8-*-importmathimportpylabaspl#數據集:每三個是一組分別是西瓜的編號,密度,含糖量data="""
1,0.697,0.46,2,0.774,0.376,3,0.634,0.264,4,0.608,0.318,5,0.556,0.215,
6,0.403,0.237,7,0.481,0.149,8,0.437,0.211,9,0.666,0.091,10,0.243,0.267,
11,0.245,0.057,12,0.343,0.099,13,0.639,0.161,14,0.657,0.198,15,0.36,0.37,
16,0.593,0.042,17,0.719,0.103,18,0.359,0.188,19,0.339,0.241,20,0.282,0.257,
21,0.748,0.232,22,0.714,0.346,23,0.483,0.312,24,0.478,0.437,25,0.525,0.369,
26,0.751,0.489,27,0.532,0.472,28,0.473,0.376,29,0.725,0.445,30,0.446,0.459"""#數據處理dataset是30個樣本(密度,含糖量)的列表a=data.split(',')
dataset=[(float(a[i]),float(a[i+1]))foriinrange(1,len(a)-1,3)]#計算歐幾里得距離,a,b分別為兩個元組defdist(a,b):
returnmath.sqrt(math.pow(a[0]-b[0],2)+math.pow(a[1]-b[1],2))#dist_mindefdist_min(Ci,Cj):
returnmin(dist(i,j)foriinCiforjinCj)#dist_maxdefdist_max(Ci,Cj):
returnmax(dist(i,j)foriinCiforjinCj)#dist_avgdefdist_avg(Ci,Cj):
returnsum(dist(i,j)foriinCiforjinCj)/(len(Ci)*len(Cj))#找到距離最小的下標deffind_Min(M):
min=1000
x=0;y=0
foriinrange(len(M)):forjinrange(len(M[i])):ifi!=jandM[i][j]<min:
min=M[i][j];x=i;y=jreturn(x,y,min)#演算法模型:defAGNES(dataset,dist,k):
#初始化C和M
C=[];M=[]foriindataset:
Ci=[]
Ci.append(i)
C.append(Ci)foriinC:
Mi=[]forjinC:
Mi.append(dist(i,j))
M.append(Mi)
q=len(dataset)#合並更新
whileq>k:
x,y,min=find_Min(M)
C[x].extend(C[y])
C.remove(C[y])
M=[]foriinC:
Mi=[]forjinC:
Mi.append(dist(i,j))
M.append(Mi)
q-=1
returnC#畫圖defdraw(C):
colValue=['r','y','g','b','c','k','m']foriinrange(len(C)):
coo_X=[]#x坐標列表
coo_Y=[]#y坐標列表
forjinrange(len(C[i])):
coo_X.append(C[i][j][0])
coo_Y.append(C[i][j][1])
pl.scatter(coo_X,coo_Y,marker='x',color=colValue[i%len(colValue)],label=i)

pl.legend(loc='upperright')
pl.show()

C=AGNES(dataset,dist_avg,3)
draw(C)

❹ python如何表述樹形結構

這是數據結構的問題,按照數據結構中樹的實現即可,當然,要是圖方便也可以使用dict來模擬

❺ python使用哪個模塊能夠解析網頁獲得DOM樹結構

三種方法:

  1. 正則表達式,python中re模塊,python自帶;

  2. pyquery,需另外安裝;

  3. beautifulsoup,需另外安裝。

具體使用上,對於比較復雜的獲取,後兩者操作更方便,前者效率更高。

❻ 求帶有樹結構的python的演算法,常見的樹結構

是不是指python里的lambda編程啊,這是面向函數的設計方法,也是樹結構

❼ python sklearn決策樹的圖怎麼畫

#coding=utf-8

from sklearn.datasets import load_iris
from sklearn import tree

iris = load_iris()
clf = tree.DecisionTreeClassifier()
clf = clf.fit(iris.data, iris.target)

from sklearn.externals.six import StringIO
import pydot

dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data)
graph = pydot.graph_from_dot_data(dot_data.getvalue())
graph[0].write_dot('iris_simple.dot')
graph[0].write_png('iris_simple.png')

❽ 如何用python將幾個列表轉換成樹形結構

不要費那個勁了,直接用pathlib

❾ 想知道如何用python語言實現一棵樹結構代碼

class node:
left=None
right=None
def __init__(self, parent=None):
self.parent=parent

賦值的時候對應就好了。如root=node(),a=node(root),root.left=a,就有點像C語言里的回指針了答。