python-igraph基本用法(一)
来源:互联网 发布:淘宝推广平台哪个好 编辑:程序博客网 时间:2024/06/08 15:51
从边列表文件生成网络
按照边列表的形式读入文件,生成无向图。
# -*- coding: utf-8 -*- #设置中文注释import igraph as ig#按照边列表的形式读入文件,生成无向图g = ig.Graph.Read_Edgelist("com-youtube.ungraph.txt", directed=False)
基本信息
ecount = g.ecount()#统计边的数目 vcount = g.vcount()#统计节点数目 maxdegree = g.maxdegree()#最大度值
计算度序列
degree()函数生成度序列
import igraph as ig#按照边列表的形式读入文件,生成无向图g = ig.Graph.Read_Edgelist("com-youtube.ungraph.txt", directed=False)degrees = g.degree()#列表#序列化度序列# f = open("youtube_degree.txt", 'w+')# for d in degrees:# print >> f,"%d" % d
类似效果:
29256122753192
生成边列表文件
get_edgelist()函数生成边列表文件,该函数可以将内存中的网络整理成边列表形式
#序列化边信息edgelist = g.get_edgelist()f = open("youtube_edgelist.txt", 'w+')for edge in edgelist: print >> f,"%d\t%d" % edge
类似效果:
1 21 31 41 51 61 71 8
邻居节点信息
给定节点
给定节点编号,求得其所有的邻居节点
neighbors = g.neighbors(vertex=1)f = open("youtube_data.txt", 'w+')try: for neighbor in neighbors: print >> f,"%d" % neighborfinally: f.close()
类似结果:
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 376, 1219, 268635, 317880, 665255, 665256, 665257, 665258]
所有节点
按照节点编号顺序依次列出所有的邻居节点,其中这列节点的标号顺序可以看做网络中边的编号。
import igraph as igg = ig.Graph.Read_Edgelist("com-youtube.ungraph.txt", directed=False)# ig.Graph.neighborhood()neighbors = g.neighborhood()# print type(neighbors)f = open("youtube_data.txt", 'a+')try: for list in neighbors: for neighbor in list[1:]:#第一个元素是当前节点,其余元素是该节点的全部邻居节点 print >> f,"%d" % neighborfinally: f.close()
阅读全文
0 0
- python-igraph基本用法(一)
- python numpy基础(一)基本用法
- python3.5-igraph实例操作(一)
- igraph基本使用方法示例
- python访问excel基本用法:openpyxl模块(一)
- python-igraph 小试牛刀
- Python学习igraph
- python 3 安装igraph
- python-igraph 安装过程
- Python R 安装 igraph
- python matplotlib 入门系列一:基本用法
- Windows下安装Python + igraph (用于复杂网络分析)
- Ubuntu 16.04安装python-igraph
- HBase基本用法 (一)
- Volley(一), 基本用法
- CoreText(一):基本用法
- tabhost基本用法(一)
- pandas基本用法(一)
- leetcode 166. Fraction to Recurring Decimal 循环小数的展开
- Java多线程总结之线程安全队列Queue
- 智能照明:蓝牙5.0将打败ZigBee?
- Java String、StringBuffer、StringBuilder
- Mapper.xml文件中如何判断多个参数不为空和null
- python-igraph基本用法(一)
- 图解归并排序
- 九度题目1040:Prime Number
- Linux中断enable_irq&enable_irq_wake
- acess denied for user 'Administrator'@'localhost' (using password: YES) 解决办法
- Effective Java 对于所有对象都通用的方法 12.考虑实现Comparable(可以比较)接口
- 数组
- C++ string提取空格之间的substring的方法
- 全国首家互联网银行——微众银行内推啦!!!技术产品各个岗位可供选择!!!最后一周!!!抓紧时间啦!!!