Skip to content

Preparation

The First Steps of Programming

First, create a python file and import net-bench. Also import networkx, because we sometimes need functions of that package.

import dsslab.net_bench
import networkx as nx

The package NetworkX is always written as networkx for the import in python and usually gets the alias nx to shorten it.

Importing a graph.

First you need to import a graph. This can be done by using a so-called Interface of the chair or with a file. For the latter option there are several formats of data, like the Pajek-format or the gexf-format, which is used by Gephi. For those forms of textfiles, NetworkX offers its own methods to convert the data into a graph of the right format:

  • read_pajek for Pajek-files
  • read_gexf for Graph Exchange XML Format
  • You can find an overview over all compatible formats here

If you want to use the interface, continue reading here.

Note

We suggest to import the data as networkx.DiGrahph in the beginning.

Clean-Up (optional)

Sometimes edges that go from the same nodes to the same nodes need to be deleted from the network. This can be done with networkx:

graph.remove_edges_from(nx.selfloop_edges(graph))

In this case, selfloops are deleted. They sometimes exist in crawled networks.