MCPcopy
hub / github.com/networkx/networkx / edges

Method edges

networkx/classes/digraph.py:970–1030  ·  view source on GitHub ↗

An OutEdgeView of the DiGraph as G.edges or G.edges(). edges(self, nbunch=None, data=False, default=None) The OutEdgeView provides set-like operations on the edge-tuples as well as edge attribute lookup. When called, it also provides an EdgeDataView object which all

(self)

Source from the content-addressed store, hash-verified

968
969 @cached_property
970 def edges(self):
971 """An OutEdgeView of the DiGraph as G.edges or G.edges().
972
973 edges(self, nbunch=None, data=False, default=None)
974
975 The OutEdgeView provides set-like operations on the edge-tuples
976 as well as edge attribute lookup. When called, it also provides
977 an EdgeDataView object which allows control of access to edge
978 attributes (but does not provide set-like operations).
979 Hence, `G.edges[u, v]['color']` provides the value of the color
980 attribute for edge `(u, v)` while
981 `for (u, v, c) in G.edges.data('color', default='red'):`
982 iterates through all the edges yielding the color attribute
983 with default `'red'` if no color attribute exists.
984
985 Parameters
986 ----------
987 nbunch : single node, container, or all nodes (default= all nodes)
988 The view will only report edges from these nodes.
989 data : string or bool, optional (default=False)
990 The edge attribute returned in 3-tuple (u, v, ddict[data]).
991 If True, return edge attribute dict in 3-tuple (u, v, ddict).
992 If False, return 2-tuple (u, v).
993 default : value, optional (default=None)
994 Value used for edges that don't have the requested attribute.
995 Only relevant if data is not True or False.
996
997 Returns
998 -------
999 edges : OutEdgeView
1000 A view of edge attributes, usually it iterates over (u, v)
1001 or (u, v, d) tuples of edges, but can also be used for
1002 attribute lookup as `edges[u, v]['foo']`.
1003
1004 See Also
1005 --------
1006 in_edges, out_edges
1007
1008 Notes
1009 -----
1010 Nodes in nbunch that are not in the graph will be (quietly) ignored.
1011 For directed graphs this returns the out-edges.
1012
1013 Examples
1014 --------
1015 >>> G = nx.DiGraph() # or MultiDiGraph, etc
1016 >>> nx.add_path(G, [0, 1, 2])
1017 >>> G.add_edge(2, 3, weight=5)
1018 >>> [e for e in G.edges]
1019 [(0, 1), (1, 2), (2, 3)]
1020 >>> G.edges.data() # default data is {} (empty dict)
1021 OutEdgeDataView([(0, 1, {}), (1, 2, {}), (2, 3, {'weight': 5})])
1022 >>> G.edges.data("weight", default=1)
1023 OutEdgeDataView([(0, 1, 1), (1, 2, 1), (2, 3, 5)])
1024 >>> G.edges([0, 2]) # only edges originating from these nodes
1025 OutEdgeDataView([(0, 1), (2, 3)])
1026 >>> G.edges(0) # only edges from node 0
1027 OutEdgeDataView([(0, 1)])

Callers 15

reverseMethod · 0.95
test_reverse_copyMethod · 0.95
test_write_read_p2gMethod · 0.95
test_digraphsMethod · 0.95
test_in_placeMethod · 0.95
test_full_join_graphFunction · 0.95
eppstein_matchingFunction · 0.95
second_order_centralityFunction · 0.95

Calls 1

OutEdgeViewClass · 0.90

Tested by 13

test_reverse_copyMethod · 0.76
test_write_read_p2gMethod · 0.76
test_digraphsMethod · 0.76
test_in_placeMethod · 0.76
test_full_join_graphFunction · 0.76
test_P5_directedMethod · 0.76
test_weighted_graphMethod · 0.76