pygmtools.utils.to_networkx

pygmtools.utils.to_networkx(adj_matrix, backend=None)[source]

Convert adjacency matrix to NetworkX object

Parameters
  • adj_matrix – the adjacency matrix to convert

  • backend – (default: pygmtools.BACKEND variable) the backend for computation.

Returns

the NetworkX object corresponding to the adjacency matrix

Example
>>> import networkx as nx
>>> import pygmtools as pygm
>>> pygm.set_backend('numpy')

# Generate adjacency matrix
>>> adj_matrix = np.random.random(size=(4,4))

# Obtain NetworkX object
>>> pygm.utils.to_networkx(adj_matrix)
<networkx.classes.digraph.DiGraph at ...>