python树形结构
❶ 【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树结构
三种方法:
正则表达式,python中re模块,python自带;
pyquery,需另外安装;
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语言里的回指针了答。