# 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.

:

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.

:

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

SVG(image)

: ## From an edge list¶

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

:

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

SVG(image)

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

:

adjacency = edgelist2adjacency(edgelist, undirected=True)

SVG(image)

: :

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

SVG(image)

: You can instantiate a bipartite graph as well.

:

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

SVG(image)

: ## 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 !