1. Edge Attributes
1.1 Methods of category
1.1.1 Basic three categories in terms of number of layers as edges or direction of edges:
import networkx as nx G = nx.DiGraph() # 1.directed G = nx.Graph() # 2.undirected
G = nx.MultiGraph() # 3.between two nodes many layers of relationships
1.1.2 Logical categories in terms of cluster characteristics:
# Bipartite
B = nx.Graph() # create an empty network first step, no subsets of nodes B.add_nodes_from([‘H‘, ‘I‘, ‘J‘, ‘K‘, ‘L‘], bipartite = 0) # label 1 group B.add_nodes_from([7, 8, 9, 10], bipartite = 1) # label 2
# add a list of edges at one time B.add_edges_from([(‘H‘, 7), (‘I‘, 7), (‘J‘, 9),(‘K‘, 8), (‘K‘, 10), (‘L‘, 10)])
# Chect if bipartite or not
bipartite.is_bipartite(B)
Bipartite graph cannot contain a cycle of an odd number of nodes.
1.2 Edge can contain detailed features.
G.add_edge(‘A‘, ‘B‘, weight = 6, relation = ‘family‘, sign = ‘+‘)
remove_edge(‘A‘, ‘B‘) # remove edge
1.3 Different dimensions to access edges output.
G.edges() # list of all edges G.edges(data = True) # list of all with attributes G.edges(data = ‘relation‘) # list with certain attribute
2. Node Attributes
2.1 Node be named as character.
G.add_node(‘A‘, name = ‘Sophie‘) G.add_node(‘B‘, name = ‘Cumberbatch‘) G.add_node(‘C‘, name = ‘Miko‘) # pet dog
2.2 Access to nodes.
G.node[‘A‘][‘name‘]
原文:https://www.cnblogs.com/sophhhie/p/12342009.html