[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [igraph] how to build a bipartite graph with python

**From**: |
Tamás Nepusz |

**Subject**: |
Re: [igraph] how to build a bipartite graph with python |

**Date**: |
Mon, 17 Jan 2011 21:45:20 +0100 |

>* I would like to build a bipartite graph with the python interface. I have the *
>* number of vertices of the first kind and the number of vertices of the second *
>* kind. *
>* *
>* What is the right syntax to combine those values and produce a bipartite *
>* graph with no links?*
Just create an empty graph with the number of vertices of the first+second
types, and add a "type" attribute whose value is 0 for vertices of the first
kind and 1 for vertices of the second kind. E.g.:
def create_bipartite(n1, n2, directed=False):
g = Graph(n1+n2, directed=directed)
g.vs["type"] = 0
g.vs[n1:]["type"] = 1
return g
Note that igraph won't stop you from adding edges between vertices of the same
type; the only reason why some igraph methods "think" that this graph is
bipartite is because of the "type" attribute.
--
Tamas