turicreate.SGraph.get_edges

SGraph.get_edges(self, src_ids=list(), dst_ids=list(), fields={}, format='sframe')

Return a collection of edges and their attributes. This function is used to find edges by vertex IDs, filter on edge attributes, or list in-out neighbors of vertex sets.

Parameters:
src_ids, dst_ids : list or SArray, optional

Parallel arrays of vertex IDs, with each pair corresponding to an edge to fetch. Only edges in this list are returned. None can be used to designate a wild card. For instance, src_ids=[1, 2, None], dst_ids=[3, None, 5] will fetch the edge 1->3, all outgoing edges of 2 and all incoming edges of 5. src_id and dst_id may be left empty, which implies an array of all wild cards.

fields : dict, optional

Dictionary specifying equality constraints on field values. For example, {'relationship': 'following'}, returns only edges whose ‘relationship’ field equals ‘following’. None can be used as a value to designate a wild card. e.g. {'relationship': None} will find all edges with the field ‘relationship’ regardless of the value.

format : {‘sframe’, ‘list’}, optional

Output format. The ‘sframe’ output (default) contains columns __src_id and __dst_id with edge vertex IDs and a column for each edge attribute. List output returns a list of Edge objects.

Returns:
out : SFrame | list [Edge]

An SFrame or list of edges.

See also

Edge, get_vertices

Examples

Return all edges in the graph.

>>> from turicreate import SGraph, Edge
>>> g = SGraph().add_edges([Edge(0, 1, attr={'rating': 5}),
                            Edge(0, 2, attr={'rating': 2}),
                            Edge(1, 2)])
>>> g.get_edges(src_ids=[None], dst_ids=[None])
+----------+----------+--------+
| __src_id | __dst_id | rating |
+----------+----------+--------+
|    0     |    2     |   2    |
|    0     |    1     |   5    |
|    1     |    2     |  None  |
+----------+----------+--------+

Return edges with the attribute “rating” of 5.

>>> g.get_edges(fields={'rating': 5})
+----------+----------+--------+
| __src_id | __dst_id | rating |
+----------+----------+--------+
|    0     |    1     |   5    |
+----------+----------+--------+

Return edges 0 –> 1 and 1 –> 2 (if present in the graph).

>>> g.get_edges(src_ids=[0, 1], dst_ids=[1, 2])
+----------+----------+--------+
| __src_id | __dst_id | rating |
+----------+----------+--------+
|    0     |    1     |   5    |
|    1     |    2     |  None  |
+----------+----------+--------+