[frames] | no frames]

# Class EdgeSeq

```  object --+
|
core.EdgeSeq --+
|
EdgeSeq
```

Class representing a sequence of edges in the graph.

This class is most easily accessed by the `es` field of the Graph object, which returns an ordered sequence of all edges in the graph. The edge sequence can be refined by invoking the EdgeSeq.select() method. EdgeSeq.select() can also be accessed by simply calling the EdgeSeq object.

An alternative way to create an edge sequence referring to a given graph is to use the constructor directly:
```>>> g = Graph.Full(3)
>>> es = EdgeSeq(g)
>>> restricted_es = EdgeSeq(g, [0, 1])
```
The individual edges can be accessed by indexing the edge sequence object. It can be used as an iterable as well, or even in a list comprehension:
```>>> g=Graph.Full(3)
>>> for e in g.es:
...   print e.tuple
...
(0, 1)
(0, 2)
(1, 2)
>>> [max(e.tuple) for e in g.es]
[1, 2, 2]
```
The edge set can also be used as a dictionary where the keys are the attribute names. The values corresponding to the keys are the values of the given attribute of every edge in the graph:
```>>> g=Graph.Full(3)
>>> for idx, e in enumerate(g.es):
...   e["weight"] = idx*(idx+1)
...
>>> g.es["weight"]
[0, 2, 6]
>>> g.es["weight"] = range(3)
>>> g.es["weight"]
[0, 1, 2]
```

 Instance Methods
` ` __call__(self, *args, **kwds)
Shorthand notation to select()
` ` select(self, *args, **kwds)
Selects a subset of the edge sequence based on some criteria

Inherited from `core.EdgeSeq`: `__delitem__`, `__getitem__`, `__init__`, `__len__`, `__new__`, `__setitem__`, `attribute_names`, `get_attribute_values`, `set_attribute_values`

Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__str__`

 Properties

Inherited from `core.EdgeSeq`: `graph`

Inherited from `object`: `__class__`

 Method Details

### __call__(self, *args, **kwds)(Call operator)

Shorthand notation to select()

This method simply passes all its arguments to EdgeSeq.select().

### select(self, *args, **kwds)

Selects a subset of the edge sequence based on some criteria

The selection criteria can be specified by the positional and the keyword arguments. Positional arguments are always processed before keyword arguments.
• If the first positional argument is `None`, an empty sequence is returned.
• If the first positional argument is a callable object, the object will be called for every edge in the sequence. If it returns `True`, the edge will be included, otherwise it will be excluded.
• If the first positional argument is an iterable, it must return integers and they will be considered as indices of the current edge set (NOT the whole edge set of the graph -- the difference matters when one filters an edge set that has already been filtered by a previous invocation of EdgeSeq.select(). In this case, the indices do not refer directly to the edges of the graph but to the elements of the filtered edge sequence.
• If the first positional argument is an integer, all remaining arguments are expected to be integers. They are considered as indices of the current edge set again.
Keyword arguments can be used to filter the edges based on their attributes. The name of the keyword specifies the name of the attribute and the filtering operator, they should be concatenated by an underscore (`_`) character. Attribute names can also contain underscores, but operator names don't, so the operator is always the largest trailing substring of the keyword name that does not contain an underscore. Possible operators are:
• `eq`: equal to
• `ne`: not equal to
• `lt`: less than
• `gt`: greater than
• `le`: less than or equal to
• `ge`: greater than or equal to
• `in`: checks if the value of an attribute is in a given list
• `notin`: checks if the value of an attribute is not in a given list
For instance, if you want to filter edges with a numeric `weight` property larger than 50, you have to write:
```>>> g.es.select(weight_gt=50)
```
Similarly, to filter edges whose `type` is in a list of predefined types:
```>>> list_of_types = ["inhibitory", "excitatory"]
>>> g.es.select(type_in=list_of_types)
```
If the operator is omitted, it defaults to `eq`. For instance, the following selector selects edges whose `type` property is `intracluster`:
```>>> g.es.select(type="intracluster")
```

In the case of an unknown operator, it is assumed that the recognized operator is part of the attribute name and the actual operator is `eq`.

Attribute names inferred from keyword arguments are treated specially if they start with an underscore (`_`). These are not real attributes but refer to specific properties of the edges, e.g., their centrality. The rule is as follows: if an attribute name starts with an underscore, the rest of the name is interpreted as a method of the Graph object. This method is called with the edge sequence as its first argument (all others left at default values) and edges are filtered according to the value returned by the method. For instance, if you want to exclude edges with a betweenness centrality less than 2:
```>>> excl = g.es.select(_edge_betweenness_ge = 2)
```
For properties that take a long time to be computed (e.g., betweenness centrality for large graphs), it is advised to calculate the values in advance and store it in a graph attribute. The same applies when you are selecting based on the same property more than once in the same `select()` call to avoid calculating it twice unnecessarily. For instance, the following would calculate betweenness centralities twice:
```>>> g.es.select(_edge_betweenness_gt=10, _edge_betweenness_lt=30)
```
```>>> g.es["bs"] = g.edge_betwenness()