Add weighted edges in `ebunch_to_add` with specified weight attr Parameters ---------- ebunch_to_add : container of edges Each edge given in the list or container will be added to the graph. The edges must be given as 3-tuples (u, v, w) wh
(self, ebunch_to_add, weight="weight", **attr)
| 1065 | nx._clear_cache(self) |
| 1066 | |
| 1067 | def add_weighted_edges_from(self, ebunch_to_add, weight="weight", **attr): |
| 1068 | """Add weighted edges in `ebunch_to_add` with specified weight attr |
| 1069 | |
| 1070 | Parameters |
| 1071 | ---------- |
| 1072 | ebunch_to_add : container of edges |
| 1073 | Each edge given in the list or container will be added |
| 1074 | to the graph. The edges must be given as 3-tuples (u, v, w) |
| 1075 | where w is a number. |
| 1076 | weight : string, optional (default= 'weight') |
| 1077 | The attribute name for the edge weights to be added. |
| 1078 | attr : keyword arguments, optional (default= no attributes) |
| 1079 | Edge attributes to add/update for all edges. |
| 1080 | |
| 1081 | See Also |
| 1082 | -------- |
| 1083 | add_edge : add a single edge |
| 1084 | add_edges_from : add multiple edges |
| 1085 | |
| 1086 | Notes |
| 1087 | ----- |
| 1088 | Adding the same edge twice for Graph/DiGraph simply updates |
| 1089 | the edge data. For MultiGraph/MultiDiGraph, duplicate edges |
| 1090 | are stored. |
| 1091 | |
| 1092 | When adding edges from an iterator over the graph you are changing, |
| 1093 | a `RuntimeError` can be raised with message: |
| 1094 | `RuntimeError: dictionary changed size during iteration`. This |
| 1095 | happens when the graph's underlying dictionary is modified during |
| 1096 | iteration. To avoid this error, evaluate the iterator into a separate |
| 1097 | object, e.g. by using `list(iterator_of_edges)`, and pass this |
| 1098 | object to `G.add_weighted_edges_from`. |
| 1099 | |
| 1100 | Examples |
| 1101 | -------- |
| 1102 | >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc |
| 1103 | >>> G.add_weighted_edges_from([(0, 1, 3.0), (1, 2, 7.5)]) |
| 1104 | |
| 1105 | Evaluate an iterator over edges before passing it |
| 1106 | |
| 1107 | >>> G = nx.Graph([(1, 2), (2, 3), (3, 4)]) |
| 1108 | >>> weight = 0.1 |
| 1109 | >>> # Grow graph by one new node, adding edges to all existing nodes. |
| 1110 | >>> # wrong way - will raise RuntimeError |
| 1111 | >>> # G.add_weighted_edges_from(((5, n, weight) for n in G.nodes)) |
| 1112 | >>> # correct way - note that there will be no self-edge for node 5 |
| 1113 | >>> G.add_weighted_edges_from(list((5, n, weight) for n in G.nodes)) |
| 1114 | """ |
| 1115 | self.add_edges_from(((u, v, {weight: d}) for u, v, d in ebunch_to_add), **attr) |
| 1116 | nx._clear_cache(self) |
| 1117 | |
| 1118 | def remove_edge(self, u, v): |
| 1119 | """Remove the edge between u and v. |