可以使用 python 的第三方图论库(如 networkx)来生成节点属性。首先,需要创建一个空的图,然后使用图中的 add_node() 方法来添加节点,并使用 set_node_attributes() 方法为节点添加属性。例如:
import networkx as nx
# Create an empty graph
G = nx.Graph()
# Add nodes to the graph
G.add_nodes_from([1, 2, 3])
# Define node attributes
node_attributes = {1: {'color': 'red', 'shape': 'circle'},
2: {'color': 'blue', 'shape': 'square'},
3: {'color': 'green', 'shape': 'triangle'}}
# Set node attributes
nx.set_node_attributes(G, node_attributes)