NetworkX

Table Of Contents

Previous topic

networkx.adjacency_spectrum

Next topic

networkx.from_whatever

Converting to and from other formats

Convert

This module provides functions to convert NetworkX graphs to and from other formats.

The preferred way of converting data to a NetworkX graph is through the graph constuctor. The constructor calls the from_whatever() function which attempts to guess the input type and convert it automatically.

Examples

Create a 10 node random graph from a numpy matrix

>>> import numpy
>>> a=numpy.reshape(numpy.random.random_integers(0,1,size=100),(10,10))
>>> D=nx.DiGraph(a) 

or equivalently

>>> D=nx.from_whatever(a,create_using=nx.DiGraph()) 

Create a graph with a single edge from a dictionary of dictionaries

>>> d={0: {1: 1}} # dict-of-dicts single edge (0,1)
>>> G=nx.Graph(d)

See Also

For graphviz dot formats see networkx.drawing.nx_pygraphviz or networkx.drawing.nx_pydot.

Functions

from_whatever(thing[, create_using, ...]) Make a NetworkX graph from an known type.
to_dict_of_lists(G[, nodelist]) Return adjacency representation of graph as a dictionary of lists
from_dict_of_lists(d[, create_using]) Return a graph from a dictionary of lists.
to_dict_of_dicts(G[, nodelist, edge_data]) Return adjacency representation of graph as a dictionary of dictionaries
from_dict_of_dicts(d[, create_using, ...]) Return a graph from a dictionary of dictionaries.
to_edgelist(G[, nodelist]) Return a list of edges in the graph.
from_edgelist(edgelist[, create_using]) Return a graph from a list of edges.
to_numpy_matrix(G[, nodelist, dtype, order]) Return the graph adjacency matrix as a NumPy matrix.
from_numpy_matrix(A[, create_using]) Return a graph from numpy matrix adjacency list.
to_scipy_sparse_matrix(G[, nodelist, dtype]) Return the graph adjacency matrix as a SciPy sparse matrix.
from_scipy_sparse_matrix(A[, create_using]) Return a graph from scipy sparse matrix adjacency list.