# Getting started¶

In scikit-network, graphs are represented by their adjacency matrix in the Compressed Sparse Row format of SciPy.

In this tutorial, we present a few methods to instantiate such inputs.

[1]:

from IPython.display import SVG

import numpy as np
from scipy import sparse

from sknetwork.visualization import svg_graph, svg_digraph, svg_bigraph


## From a NumPy array¶

For small graphs, you can instantiate the adjacency matrix as a dense NumPy array and convert it into a sparse matrix in CSR format.

[2]:

adjacency = np.array([[0, 1, 1, 0], [1, 0, 1, 1], [1, 1, 0, 0], [0, 1, 0, 0]])

SVG(image)

[2]:


## From an edge list¶

Another natural way to build a graph is from a list of edges.

[3]:

edgelist = [(0, 1), (1, 2), (2, 3), (3, 0), (0, 2)]

SVG(image)

[3]:


By default, the graph is treated as directed, but you can easily make it undirected.

[4]:

adjacency = edgelist2adjacency(edgelist, undirected=True)

SVG(image)

[4]:


[5]:

edgelist = [(0, 1, 1), (1, 2, 0.5), (2, 3, 1), (3, 0, 0.5), (0, 2, 2)]

SVG(image)

[5]:


You can instantiate a bipartite graph as well.

[6]:

edgelist = [(0, 0), (1, 0), (1, 1), (2, 1)]

SVG(image)

[6]:


## From a NetworkX object¶

NetworkX has import and export functions from and towards the CSR format.

## Other options¶

• You have a TSV file containing a list of edges

• You have a GraphML file

• You want to test our toy graphs

• You want to generate a graph from a model

• You want to load a graph from one of our referenced repositories (see NetSets and KONECT)

Take a look at the tutorials of the data section !