Package igraph :: Class VertexSeq
[hide private]
[frames] | no frames]

Class VertexSeq

    object --+    
             |    
core.VertexSeq --+
                 |
                VertexSeq

Class representing a sequence of vertices in the graph.

This class is most easily accessed by the vs field of the Graph object, which returns an ordered sequence of all vertices in the graph. The vertex sequence can be refined by invoking the VertexSeq.select() method. VertexSeq.select() can also be accessed by simply calling the VertexSeq object.

An alternative way to create a vertex sequence referring to a given graph is to use the constructor directly:

>>> g = Graph.Full(3)
>>> vs = VertexSeq(g)
>>> restricted_vs = VertexSeq(g, [0, 1])

The individual vertices can be accessed by indexing the vertex sequence object. It can be used as an iterable as well, or even in a list comprehension:

>>> g=Graph.Full(3)
>>> for v in g.vs:
...   v["value"] = v.index ** 2
...
>>> [v["value"] ** 0.5 for v in g.vs]
[0.0, 1.0, 2.0]

The vertex 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 for every vertex selected by the sequence.

>>> g=Graph.Full(3)
>>> for idx, v in enumerate(g.vs):
...   v["weight"] = idx*(idx+1)
...
>>> g.vs["weight"]
[0, 2, 6]
>>> g.vs.select(1,2)["weight"] = [10, 20]
>>> g.vs["weight"]
[0, 10, 20]

Some methods of the vertex sequences are simply proxy methods to the corresponding methods in the Graph object. One such example is VertexSeq.degree():

>>> g=Graph.Tree(7, 2)
>>> g.vs.degree()
[2, 3, 3, 1, 1, 1, 1]
>>> g.vs.degree() == g.degree()
True
Instance Methods [hide private]
 
__call__(self, *args, **kwds)
Shorthand notation to select()
 
betweenness(*args, **kwds)
Proxy method to Graph.betweenness()
 
bibcoupling(*args, **kwds)
Proxy method to Graph.bibcoupling()
 
closeness(*args, **kwds)
Proxy method to Graph.closeness()
 
cocitation(*args, **kwds)
Proxy method to Graph.cocitation()
 
constraint(*args, **kwds)
Proxy method to Graph.constraint()
 
degree(*args, **kwds)
Proxy method to Graph.degree()
 
eccentricity(*args, **kwds)
Proxy method to Graph.eccentricity()
 
get_shortest_paths(*args, **kwds)
Proxy method to Graph.get_shortest_paths()
 
indegree(*args, **kwds)
Proxy method to Graph.indegree()
 
isoclass(*args, **kwds)
Proxy method to Graph.isoclass()
 
maxdegree(*args, **kwds)
Proxy method to Graph.maxdegree()
 
outdegree(*args, **kwds)
Proxy method to Graph.outdegree()
 
pagerank(*args, **kwds)
Proxy method to Graph.pagerank()
VertexSeq
select(self, *args, **kwds)
Selects a subset of the vertex sequence based on some criteria
 
shortest_paths(*args, **kwds)
Proxy method to Graph.shortest_paths()
 
similarity_dice(*args, **kwds)
Proxy method to Graph.similarity_dice()
 
similarity_jaccard(*args, **kwds)
Proxy method to Graph.similarity_jaccard()
 
subgraph(*args, **kwds)
Proxy method to Graph.subgraph()

Inherited from core.VertexSeq: __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 [hide private]

Inherited from core.VertexSeq: graph, indices

Inherited from object: __class__

Method Details [hide private]

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

 

Shorthand notation to select()

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

betweenness(*args, **kwds)

 

Proxy method to Graph.betweenness()

This method calls the betweenness() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.betweenness() for details.

bibcoupling(*args, **kwds)

 

Proxy method to Graph.bibcoupling()

This method calls the bibcoupling() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.bibcoupling() for details.

closeness(*args, **kwds)

 

Proxy method to Graph.closeness()

This method calls the closeness() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.closeness() for details.

cocitation(*args, **kwds)

 

Proxy method to Graph.cocitation()

This method calls the cocitation() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.cocitation() for details.

constraint(*args, **kwds)

 

Proxy method to Graph.constraint()

This method calls the constraint() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.constraint() for details.

degree(*args, **kwds)

 

Proxy method to Graph.degree()

This method calls the degree() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.degree() for details.

eccentricity(*args, **kwds)

 

Proxy method to Graph.eccentricity()

This method calls the eccentricity() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.eccentricity() for details.

get_shortest_paths(*args, **kwds)

 

Proxy method to Graph.get_shortest_paths()

This method calls the get_shortest_paths() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.get_shortest_paths() for details.

indegree(*args, **kwds)

 

Proxy method to Graph.indegree()

This method calls the indegree() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.indegree() for details.

isoclass(*args, **kwds)

 

Proxy method to Graph.isoclass()

This method calls the isoclass() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.isoclass() for details.

maxdegree(*args, **kwds)

 

Proxy method to Graph.maxdegree()

This method calls the maxdegree() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.maxdegree() for details.

outdegree(*args, **kwds)

 

Proxy method to Graph.outdegree()

This method calls the outdegree() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.outdegree() for details.

pagerank(*args, **kwds)

 

Proxy method to Graph.pagerank()

This method calls the pagerank() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.pagerank() for details.

select(self, *args, **kwds)

 

Selects a subset of the vertex 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 vertex in the sequence. If it returns True, the vertex 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 vertex set (NOT the whole vertex set of the graph -- the difference matters when one filters a vertex set that has already been filtered by a previous invocation of VertexSeq.select(). In this case, the indices do not refer directly to the vertices of the graph but to the elements of the filtered vertex 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 vertex set again.

Keyword arguments can be used to filter the vertices 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 vertices with a numeric age property larger than 200, you have to write:

>>> g.vs.select(age_gt=200)

Similarly, to filter vertices whose type is in a list of predefined types:

>>> list_of_types = ["HR", "Finance", "Management"]
>>> g.vs.select(type_in=list_of_types)

If the operator is omitted, it defaults to eq. For instance, the following selector selects vertices whose cluster property equals to 2:

>>> g.vs.select(cluster=2)

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 vertices, e.g., its degree. 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 vertex sequence as its first argument (all others left at default values) and vertices are filtered according to the value returned by the method. For instance, if you want to exclude isolated vertices:

>>> non_isolated = g.vs.select(_degree_gt=0)

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.vs.select(_betweenness_gt=10, _betweenness_lt=30)

It is advised to use this instead:

>>> g.vs["bs"] = g.betwenness()
>>> g.vs.select(bs_gt=10, bs_lt=30)
Returns: VertexSeq
the new, filtered vertex sequence
Overrides: core.VertexSeq.select

shortest_paths(*args, **kwds)

 

Proxy method to Graph.shortest_paths()

This method calls the shortest_paths() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.shortest_paths() for details.

similarity_dice(*args, **kwds)

 

Proxy method to Graph.similarity_dice()

This method calls the similarity_dice() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.similarity_dice() for details.

similarity_jaccard(*args, **kwds)

 

Proxy method to Graph.similarity_jaccard()

This method calls the similarity_jaccard() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.similarity_jaccard() for details.

subgraph(*args, **kwds)

 

Proxy method to Graph.subgraph()

This method calls the subgraph() method of the Graph class restricted to this sequence, and returns the result.

See Also: Graph.subgraph() for details.