Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a directed graph using python-igraph [closed]

Tags:

python

igraph

I have 2 Node types, where TypeA will always point to TypeB, TypeB has no outbound edges.

How can I indicate this as a directed graph using igraph?

like image 418
George L Avatar asked Dec 25 '15 18:12

George L


People also ask

How do you plot a graph in an igraph in Python?

First, you will need to install python-igraph if you do not have it already installed. You can use pip. You will also need to install cairocffi to plot the graphs. If you are using a Python package manager such as Anaconda or Miniconda, you can install python-igraph using the conda install command.

How do you create a directed graph in Python?

Add the nodes from any container (a list, dict, set or even the lines from a file or the nodes from another graph). In addition to strings and integers any hashable Python object (except None) can represent a node, e.g. a customized node object, or even another Graph. Edges: G can also be grown by adding edges.

Which is better igraph or NetworkX?

The igraph library requires less resources for compilation, and comes with additional bindings for the R and C languages which the other two lack. NetworkX is comparatively very inefficient, but it is trivial to install --- requiring no compilation at all, since it is pure python.

Are directed graphs with no cycles?

A graph without cycles is called an acyclic graph. A directed graph without directed cycles is called a directed acyclic graph. A connected graph without cycles is called a tree.


1 Answers

https://igraph.org/python/doc/tutorial/generation.html#from-nodes-and-edges

g = Graph(directed=True)
g.add_vertices(2)
g.add_edges([(0,1)])
g.degree(mode="in")     # -> [0, 1]
g.degree(mode="out")    # -> [1, 0]
like image 134
kliron Avatar answered Sep 18 '22 02:09

kliron