Python学习igraph
来源:互联网 发布:剑网三男捏脸数据 编辑:程序博客网 时间:2024/05/18 01:10
总结:学习一种全新的语言看官方的文档是真的很有帮助,这次我的大部分python代码的完成都是靠着igraph官方的API文档。
官方API:http://pythonhosted.org/python-igraph/igraph.Graph-class.html
首先导入igraph工具包 from igraph import *(python语法)
创建图 g = Graph.Tree(127, 2)
运行fastunfloding算法 g.community_multilevel("weight",True)
绘制graph plot(g)
代码参考 fastunfloding.txt
给图添加边并且添加权值:g.add_edges([(0,1)])
g.es[1]["weight"]=2
其中g.es[1]代表的是第一条边
最开始我的图是从数据库导出,即(点,点,权)这种模式所以就需要从txt文档中读边并且建立图
打开文件:f = open('D:\\test1\\test.txt','r')
读文件中一行:line = f.readline() 注:line是字符串的形式
取出文件一行的整数并且加入到数组尾部 result.append(map(int,line.split(',')))
读图完毕后就需要将图放到fastunfolding算法中去了
a = g.community_multilevel("weight",True)
官方API上说 当g.community_multilevel最后一个参数为True的时候
a返回的是一组list,list的存放位置在(a[0])处,a[0][s]代表着
community为s的所有顶点
注:a list of VertexClustering objects, one corresponding to each level (if return_levels is True)
取list长度:len(a[0])
将输入的图存成gml格式:g.write_graphmlz(self, f, compresslevel=9)
读gml格式的图:g = Graph.Read_GraphMLz("D:\\test1\\final_graph.gml")
官方API:http://pythonhosted.org/python-igraph/igraph.Graph-class.html
首先导入igraph工具包 from igraph import *(python语法)
创建图 g = Graph.Tree(127, 2)
运行fastunfloding算法 g.community_multilevel("weight",True)
绘制graph plot(g)
代码参考 fastunfloding.txt
给图添加边并且添加权值:g.add_edges([(0,1)])
g.es[1]["weight"]=2
其中g.es[1]代表的是第一条边
最开始我的图是从数据库导出,即(点,点,权)这种模式所以就需要从txt文档中读边并且建立图
打开文件:f = open('D:\\test1\\test.txt','r')
读文件中一行:line = f.readline() 注:line是字符串的形式
取出文件一行的整数并且加入到数组尾部 result.append(map(int,line.split(',')))
读图完毕后就需要将图放到fastunfolding算法中去了
a = g.community_multilevel("weight",True)
官方API上说 当g.community_multilevel最后一个参数为True的时候
a返回的是一组list,list的存放位置在(a[0])处,a[0][s]代表着
community为s的所有顶点
注:a list of VertexClustering objects, one corresponding to each level (if return_levels is True)
取list长度:len(a[0])
将输入的图存成gml格式:g.write_graphmlz(self, f, compresslevel=9)
读gml格式的图:g = Graph.Read_GraphMLz("D:\\test1\\final_graph.gml")
1 0
- Python学习igraph
- python-igraph 小试牛刀
- python 3 安装igraph
- python-igraph 安装过程
- Python R 安装 igraph
- Ubuntu 16.04安装python-igraph
- python igraph whl文件的安装
- windows环境安装python igraph包
- python-igraph基本用法(一)
- windows环境安装python-igraph全过程
- igraph/networkx学习笔记之…
- Windows下安装Python + igraph (用于复杂网络分析)
- linux ubuntu 安装/卸载/删除python-igraph方法
- igraph/networkx学习笔记之一 —— 数据结构
- igraph/networkx学习笔记之一 ——数据结构
- R语言学习-提取igraph的节点和边
- igraph study
- windows下python 安装igraph库报错 Cannot find the C core of igraph on this system using pkg-config.的解决
- 国生教育:备考自考英语 计划大于一切
- 14个SAT数学重要公式
- 美轮美奂宇宙星空制作神器Spacescape
- ACDSee v9.0.108 中文破解版下载
- 数组中出现次数超过一半的数字
- Python学习igraph
- eclipse自动更新svn方法
- 将UIImage转化成NSData在转化成NSString(将UIImage转化成Base64的字节流)
- Kalman滤波各参数的一些调整
- RAID磁盘阵列
- 第十四周项目二——用文件保存的学生名单
- 不同机子tcp报文转发
- 文科生也能看懂的iptables教程(推荐)
- ios-通知:闹钟之关于设置闹钟后,点击app图标进入程序不播放音乐的问题(已解决)