'DiGraph' object has no attribute 'values'
时间: 2023-06-21 22:11:46 浏览: 213
digraph:非常简单的C ++定向图库
The error message "'DiGraph' object has no attribute 'values'" usually occurs when you try to access the 'values' attribute of a DiGraph object in NetworkX, but the attribute does not exist.
In NetworkX, the 'values' attribute is only available for nodes and edges, not for the graph itself. To access the values of the nodes or edges in your DiGraph object, you can use the 'node[n]['attribute']' or 'edge[u][v]['attribute']' syntax, where 'n' is the node ID, 'u' and 'v' are the source and target node IDs of an edge, and 'attribute' is the name of the attribute you want to access.
Here's an example of how to access the node attributes in a DiGraph object:
``` python
import networkx as nx
# Create a DiGraph object
G = nx.DiGraph()
# Add some nodes with attributes
G.add_node(1, color='red', size=10)
G.add_node(2, color='blue', size=5)
# Access the attributes of node 1
print(G.nodes[1]['color']) # Output: 'red'
print(G.nodes[1]['size']) # Output: 10
```
If you're still having trouble with the 'values' attribute, you can try checking the NetworkX documentation or posting a more detailed question with your code and error message.
阅读全文