networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersBackRef
set_edge_attributes(G, values, name=None)
.. Warning:: The call order of arguments `values` and `name`
    switched between v1.x & v2.x.

Parameters

G : NetworkX Graph
values : scalar value, dict-like

What the edge attribute should be set to. If :None:None:`values` is not a dictionary, then it is treated as a single attribute value that is then applied to every edge in G. This means that if you provide a mutable object, like a list, updates to that object will be reflected in the edge attribute for each edge. The attribute name will be :None:None:`name`.

If :None:None:`values` is a dict or a dict of dict, it should be keyed by edge tuple to either an attribute value or a dict of attribute key/value pairs used to update the edge's attributes. For multigraphs, the edge tuples must be of the form (u, v, key) , where u and v are nodes and :None:None:`key` is the edge key. For non-multigraphs, the keys must be tuples of the form (u, v) .

name : string (optional, default=None)

Name of the edge attribute to set if values is a scalar.

Sets edge attributes from a given value or dictionary of values.

Examples

>>> G = nx.path_graph(3)
>>> bb = nx.edge_betweenness_centrality(G, normalized=False)
>>> nx.set_edge_attributes(G, bb, "betweenness")
>>> G.edges[1, 2]["betweenness"]
2.0
>>> labels = []
>>> nx.set_edge_attributes(G, labels, "labels")
>>> labels.append("foo")
>>> G.edges[0, 1]["labels"]
['foo']
>>> G.edges[1, 2]["labels"]
['foo']
>>> G = nx.path_graph(3)
>>> attrs = {(0, 1): {"attr1": 20, "attr2": "nothing"}, (1, 2): {"attr2": 3}}
>>> nx.set_edge_attributes(G, attrs)
>>> G[0][1]["attr1"]
20
>>> G[0][1]["attr2"]
'nothing'
>>> G[1][2]["attr2"]
3
>>> G = nx.Graph([(0, 1)])
>>> nx.set_edge_attributes(G, {(1, 2): {"weight": 2.0}})
>>> (1, 2) in G.edges()
False
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.flow.gomory_hu.gomory_hu_tree networkx.algorithms.shortest_paths.astar.astar_path networkx.algorithms.operators.binary.compose networkx.algorithms.approximation.traveling_salesman.asadpour_atsp

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/classes/function.py#726
type: <class 'function'>
Commit: