evansyangs evansyangs
首页
分类
标签
归档
GitHub (opens new window)

Evan Yang

摸鱼小能手
首页
分类
标签
归档
GitHub (opens new window)
  • NetworkX Learning Notes
  • 1. Creating a graph
  • 2. Nodes
  • 3. Edges
  • 4. What to use as nodes and edges
  • 5. Accessing edges and neighbors
  • 6. Adding attributes to graphs, nodes, and edges
  • 7. Analyzing graphs
  • 8. Directed graphs
  • 9. Drawing graphs
  • 10. Graph generators and graph operations
  • 11. Multigraphs

11. Multigraphs

NetworkX provides classes for graphs which allow multiple edges between any pair of nodes. The MultiGraph (opens new window) and MultiDiGraph (opens new window) classes allow you to add the same edge twice, possibly with different edge data. This can be powerful for some applications, but many algorithms are not well defined on such graphs. Where results are well defined, e.g., MultiGraph.degree() (opens new window) we provide the function. Otherwise you should convert to a standard graph in a way that makes the measurement well defined.

MG = nx.MultiGraph()
MG.add_weighted_edges_from([(1, 2, 0.5), (1, 2, 0.75), (2, 3, 0.5)])
dict(MG.degree(weight='weight'))

GG = nx.Graph()
for n, nbrs in MG.adjacency():
   for nbr, edict in nbrs.items():
       minvalue = min([d['weight'] for d in edict.values()])
       GG.add_edge(n, nbr, weight = minvalue)

nx.shortest_path(GG, 1, 3)
1
2
3
4
5
6
7
8
9
10
11
编辑 (opens new window)
#Python
上次更新: 2021/02/16, 02:45:37
10. Graph generators and graph operations

← 10. Graph generators and graph operations

最近更新
01
Dell7472黑苹果
03-27
02
上手HackMD
04-13
03
Windows Terminal设置
03-14
更多文章>
Theme by Vdoing | Copyright © 2019-2023 Evan Yang
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式