摘要: nx.draw()方法,至少接受一个参数:待绘制的网络G参数:运行样式: - `node_size`: 指定节点的尺寸大小(默认是300) - `node_color`: 指定节点的颜色 (默认是红色,可以用字符串简单标识颜色,例如'r'为红色,'b'为绿色等) - `node_shape`: 节点的形状(默认是圆形,用字符串'o'标识) - `alpha`: 透明度 (默认是1.0,不透明,0为完全透明) - `width`: 边的宽度 (默认为1.0) - `edge_color`: 边的颜色(默认为黑色) - `style`: 边的样式(默 阅读全文
posted @ 2012-03-20 16:20 Alex_Monkey 阅读(4194) 评论(0) 推荐(1) 编辑
摘要: NetworkX提供了4种常见网络的建模方法,分别是:规则图,ER随机图,WS小世界网络和BA无标度网络。一. 规则图 规则图差不多是最没有复杂性的一类图,random_graphs.random_regular_graph(d, n)方法可以生成一个含有n个节点,每个节点有d个邻居节点的规则图。 下面一段示例代码,生成了包含20个节点、每个节点有3个邻居的规则图: 1 import networkx as nx 2 import matplotlib.pyplot as plt 3 4 # regular graphy 5 # generate a regular graph wh... 阅读全文
posted @ 2012-03-20 14:55 Alex_Monkey 阅读(51115) 评论(1) 推荐(0) 编辑
摘要: 1 # Filename: stat_indictors.py 2 3 import networkx as nx 4 5 # generate a n = 1000, m = 3 BA scale-free network 6 G = nx.random_graphs.barabasi_albert_graph(1000, 3) 7 print G.degree(0) # return node0's degree 8 print G.degree() # return all node's degree 9 # return all node's distribut 阅读全文
posted @ 2012-03-19 21:45 Alex_Monkey 阅读(2509) 评论(1) 推荐(1) 编辑
摘要: 1 # Filename: youxiangtu.py 2 3 # NetworkX 4 import networkx as nx 5 6 # establish a null undirected graphy 7 G = nx.Graph() # directed graphy: G = nx.DiGraph() 8 # add node1 9 G.add_node(1)10 # add edge2-3(also add node2 node3)11 G.add_edge(2, 3)12 # add edge3-2 13 G.add_edge(3, 2) # undirected... 阅读全文
posted @ 2012-03-19 21:44 Alex_Monkey 阅读(1055) 评论(0) 推荐(0) 编辑
摘要: Python标准库Python标准库是随Python附带安装的。这些模块可以解决大部分的问题。1.sys模块:包含系统对应的功能。使用sys.args即命令行参数一下代码类似cat功能,命令参数为“--version”或“-help”时,打印相关说明;为文件时,打印其内容。 1 # Filename: cat.py 2 import sys 3 def readfile(filename): 4 '''Print a file to the standard output.''' 5 f = file(filename) 6 while True 阅读全文
posted @ 2012-03-18 22:06 Alex_Monkey 阅读(712) 评论(0) 推荐(0) 编辑
摘要: 面向对象类中的属性: 域和方法类的方法的第一个参数为self(类似于this指针),调用时无需写明__init__方法,在类的对象被建立时,马上运行。(类似于构造函数)def __init__(slef, name):__del__方法,(类似于析构函数)有两种类型的 域:类的变量和对象的变量(类似于c#中静态变量),是否有self来区分两者。python中所有类成员是公共的,方法是有效地。例外:双下划线为前缀的数据成员是私有的。继承: 1 # Filename: inherit.py 2 class SchoolMember: 3 "'Represents any scho 阅读全文
posted @ 2012-03-17 22:05 Alex_Monkey 阅读(295) 评论(0) 推荐(0) 编辑
摘要: 一个归档的小程序。 1 # Filename: backup_ver3 2 import os 3 import time 4 #import sys 5 #reload(sys) 6 #sys.setdefaultencoding('utf8') 7 # 1. The files and directories to be backed up are specified in a list. 8 source = ['C:\\networkx.txt', 'c:\\backup\\'] 9 10 # 2. The backip must be 阅读全文
posted @ 2012-03-17 18:57 Alex_Monkey 阅读(320) 评论(0) 推荐(0) 编辑
摘要: python中有三种内部数据结构:列表、元组、字典(using_list.py,using_tuple.py, using——dict.py)list:列表。shoplist = ['apple', 'mango', 'carrot', 'banana'] 方法,尾部添加shoplist.append('rice'),排序shoplist.sort(),删除del shoplist[i] 1 # Filename: using_list.py 2 # This is my shopping list 3 shopl 阅读全文
posted @ 2012-03-17 14:05 Alex_Monkey 阅读(1593) 评论(0) 推荐(0) 编辑
摘要: python中有四种类型的数:整形 长整型 浮点数 复数python用缩进来标示语句块字符串下一行继续用 \"This is the first sentence.\This is the second sentence."自然字符串即非转义字符串,加前缀r或Rr"hello, world"unicode编码加前缀u或Uu"This is a unicode string"级联字符串'What\'s' 'your name?' = "What's your name?" 阅读全文
posted @ 2012-03-17 00:54 Alex_Monkey 阅读(381) 评论(0) 推荐(0) 编辑
摘要: PATH:保存了shell查找命令的目录列表HOME:登录路径特殊的shell变量:$0 获取当前执行的shell脚本的文件名$n 获取当前执行的shell脚本的第n个参数值,n=1..9$* 获取当前shell的所有参数 “$1 $2 $3 …注意与$#的区别$# 获取当前shell命令行中参数的总个数$$ 获取当前shell的进程号(PID)$! 执行上一个指令的PID$? 获取执行的上一个指令的返回值(0 为成功, 非零为失败)这些shell变量可以自己创建、访问、修改shell的内部命令可以显示你定义的所有变量的值一个变量的值域创建它的shell有关,该值不会传递给子shell但可以在 阅读全文
posted @ 2011-11-15 23:23 Alex_Monkey 阅读(267) 评论(0) 推荐(0) 编辑