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

2. Nodes

The graph G can be grown in several ways. NetworkX includes many graph generator functions and facilities to read and write graphs in many formats. To get started though we’ll look at simple manipulations. You can add one node at a time,

G.add_node(1)
1

add a list of nodes,

G.add_nodes_from([2, 3])
1

or add any iterable container of nodes. You can also add nodes along with node attributes if your container yields 2-tuples (node, node_attribute_dict). Node attributes are discussed further below.

H = nx.path_graph(10)
G.add_nodes_from(H)
1
2

提示

Note that G now contains the nodes of H as nodes of G. In contrast, you could use the graph H as a node in G.

G.add_node(H)
1

The graph G now contains H as a node. This flexibility is very powerful as it allows graphs of graphs, graphs of files, graphs of functions and much more. It is worth thinking about how to structure your application so that the nodes are useful entities. Of course you can always use a unique identifier in G and have a separate dictionary keyed by identifier to the node information if you prefer.

提示

You should not change the node object if the hash depends on its contents.

编辑 (opens new window)
#Python
上次更新: 2021/02/16, 02:45:37
1. Creating a graph
3. Edges

← 1. Creating a graph 3. Edges→

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