python networkx 已创建的图怎么查看它的所有边

>>>G=nx.Graph()#orDiGraph,MultiGraph,MultiDiGraph,etc
>>>G.add_path([0,1,2])
>>>G.add_edge(2,3,weight=5)
>>>G.edges()
[(0,1),(1,2),(2,3)]
>>>G.edges(data=True)#defaultedgedatais{}(emptydictionary)
[(0,1,{}),(1,2,{}),(2,3,{'weight':5})]
>>>list(G.edges_iter(data='weight',default=1))
[(0,1,1),(1,2,1),(2,3,5)]
>>>G.edges([0,3])
[(0,1),(3,2)]
>>>G.edges(0)
[(0,1)]

㈡ 如何在Windows操作系统下安装Python和Networkx

Networkx是一套基于Python的多种网络构造库。因为之前没有学过Python,因此一点点上手,这一篇讲一讲如何在Windows环境下安装Python2.7和Networkx。

首先要澄清一下,如果是想深入系统学习Python的同学,还是尽早换Linux系统,因为Windows底下的库安装非常麻烦;而Linux底下只需要运行命令行(Terminal):
sudo apt-get install python-matplotlib

就可以了。

由于仅仅是使用Networkx构造数据的关系,以下简单说明如何在Windows底下快速地安装和使用Python2.7。

0. 先留个记号:Python的初学者指南
https://wiki.python.org/moin/BeginnersGuide

1. 下载Python 2.7,双击安装
https://www.python.org/downloads/windows/
添加路径变量:在<开始>菜单 - Control Panel - System and Security - System - Advanced System Settings - (Advanced Tab) - Environmental Variables - 找到‘Path’,双击打开 - 添加路径‘C:\Python27’(系统安装文件夹),一路确定。

确认安装:在<开始>菜单 - 运行cmd - 进入命令行,输入‘python’,显示
Python 2.7.8 (default, Jun 30 2014, 16:08:48)
即安装成功。
(输入exit()退出Python)

2. 安装networkx之前,需要下载并安装setuptools,下载地址:
https://pypi.python.org/pypi/setuptools
放到Python27的文件夹下,双击自动安装。

3. 下载networkx,解压文件夹,复制到Python27的文件夹下:
https://pypi.python.org/pypi/networkx/
在cmd窗口命令行下进入networkx的文件夹,输入‘python setup.py install’ 安装networkx库。
安装程序完成。

4. 测试程序:
在cmd任何路径下进入python,使用小测试程序确认安装成功!
http://networkx.github.io/examples.html
程序如下:
>>> import networkx as nx
>>> G=nx.Graph()
>>> G.add_node("spam")
>>> G.add_edge(1,2)
>>> print(G.nodes())
[1, 2, 'spam']
>>> print(G.edges())
[(1, 2)]

5. 附networkx的Tutorial:
https://networkx.github.io/documentation/latest/overview.html
networkx网络生成函数:
http://networkx.lanl.gov/reference/generators.html#mole-networkx.generators.random_graphs

㈢ python networkx报错AttributeError:

你把代码发上来看看,下面一个例子


importnetworkxasnx

G=nx.Graph()#建立一个空的无向图G
G.add_node(1)#添加一个节点1
G.add_edge(2,3)#添加一条边2-3(隐含着添加了两个节点2、3)
G.add_edge(3,2)#对于无向图,边3-2与边2-3被认为是一条边
print"nodes:",G.nodes()#输出全部的节点:[1,2,3]
print"edges:",G.edges()#输出全部的边:[(2,3)]
print"numberofedges:",G.number_of_edges()#输出边的数量:1

㈣ python的networkx怎么给边加注释

应该是不可以的
#!/usr/bin/env python
"""
Draw a graph with matplotlib.
You must have matplotlib for this to work.
"""
__author__ = """Aric Hagberg ([email protected])"""
try:
import matplotlib.pyplot as plt
except:
raise
import networkx as nx
G=nx.house_graph()
# explicitly set positions
pos={0:(0,0),
1:(1,0),
2:(0,1),
3:(1,1),
4:(0.5,2.0)}
nx.draw_networkx_nodes(G,pos,node_size=2000,nodelist=[4])
nx.draw_networkx_nodes(G,pos,node_size=3000,nodelist=[0,1,2,3],node_color='b')
nx.draw_networkx_edges(G,pos,alpha=0.5,width=6)
plt.axis('off')
plt.savefig("house_with_colors.png") # save as png
plt.show() # display

㈤ python networkx模块里面计算最短路径时,如何处理等价路径我怎么测试只能显示1条路径,请大神赐教。

if source is None: if target is None: ## Find paths between all pairs. if weight is None: paths=nx.all_pairs_shortest_path(G) else: paths=nx.all_pairs_dijkstra_path(G,weight=weight) else: ## Find paths from all nodes co-accessible to the target. directed = G.is_directed() if directed: G.reverse(=False) if weight is None: paths=nx.single_source_shortest_path(G,target) else: paths=nx.single_source_dijkstra_path(G,target,weight=weight) # Now flip the paths so they go from a source to the target. for target in paths: paths[target] = list(reversed(paths[target])) if directed: G.reverse(=False) else: if target is None: ## Find paths to all nodes accessible from the source. if weight is None: paths=nx.single_source_shortest_path(G,source) else: paths=nx.single_source_dijkstra_path(G,source,weight=weight) else: ## Find shortest source-target path. if weight is None: paths=nx.bidirectional_shortest_path(G,source,target) else: paths=nx.dijkstra_path(G,source,target,weight)

㈥ python networkx 程序运行

有这句了吗
import matplotlib.pyplot as plt
因为从代码上看不到plt的的相关说明

㈦ python networkx 都可以干什么

1 import networkx
2 _of_edges()
3 #建图
4 G = networkx.Graph()
5 #节点数:
6 len(G)
7 #边数
8 G.number_of_edges()
9 #节点表
10 G.nodes()
11 #边表
12 G.edges()
13 #网络直径
14 diameter(G)
15 #所有节点间的最短*路径*,列表存储
16 networkx.all_pairs_shortest_path(G)

㈧ 怎样基于python networkx实现社区发现

k_clique_communities的input是G,networkx的graph的数据结构。 所以原链接的test.txt文件应该是包涵一个graph的文件。

networkx可以读取的graph文件种类如链接所示。Reading and writing graphs

常见的类型有edgelist (usually stored as a text file)和GML。如果我们用Network data 的dolphins social network (which is stored as a GML file)做例子的话,运行如下的code:

import networkx as nx import matplotlib.pyplot as plt G = nx.read_gml('dolphins.gml')klist = list(nx.k_clique_communities(G,3)) #list of k-cliques in the network. each element contains the nodes that consist the clique.#plottingpos = nx.spring_layout(G)plt.clf()nx.draw(G,pos = pos, with_labels=False)nx.draw(G,pos = pos, nodelist = klist[0], node_color = 'b')nx.draw(G,pos = pos, nodelist = klist[1], node_color = 'y')plt.show()

我们的到如下结果:


&lt;img src="https://pic3.mg.com/50/v2-_hd.png" data-rawwidth="800" data-rawheight="600" class="origin_image zh-lightbox-thumb" width="800" data-original="https://pic3.mg.com/v2-_r.png"&gt;

which gives us four clique communities.

㈨ 使用Python调用networkx时出现这个问题怎么解决

这是基础都还没学就开始人工智能 神经网络了吗

㈩ python networkx 使用import community 报错没有community这个模块

from networkx.algorithms import community