ipython 学习笔记 2 network graph--NetworkX

如果NetworkX不好用,pip uninstall 然后install

1) 看每个node的social情况

In [1]: import networkx as nx

In [2]: nx.read<点击TAB看选项> 比如

nx.read_adjlist nx.read_dot nx.read_edgelist



这个时候应该在有一系列edges和dot的文件夹 fbdata里

In [3]: g = nx.read_edgelist('0.edges')

此时g继承了read的各种method,查看g的情况

In [5]: len(g.nodes()), len(g.edges())

Out[5]: (333, 2519)


The 0 ego user then appears to have 333 friends(nodes), and there are 2519 connections(edges) between these friends. 

2) 看social network的structure

sg = nx.connected_component_subgraphs(g)

[len(s) for s in sg]

这里因为sg是个generator object 书上的用法不对,但是我不知道怎么改

s1 =list(sg)

s1 = s1[0]

nx.radius(sg), nx.diameter(sg)



可能是版本问题,

 

你可能感兴趣的:(NetWork)