pygmtools.utils.to_graphml

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

Write an adjacency matrix to a GraphML file

Parameters
  • adj_matrix – numpy.ndarray, the adjacency matrix to write

  • filename – str, the name of the output file

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

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

# Generate adjacency matrix
>>> adj_matrix = np.random.random(size=(4,4))
>>> filename = 'examples/data/test.graphml'
>>> adj_matrix
array([[0.29440151, 0.66468829, 0.05403941, 0.85887567],
       [0.48120964, 0.01429095, 0.73536659, 0.02962113],
       [0.3815578 , 0.93356234, 0.01332568, 0.61149257],
       [0.15422904, 0.64656912, 0.93219422, 0.784769  ]])

# Write GraphML file
>>> pygm.utils.to_graphml(adj_matrix, filename)

# Check the generated GraphML file
>>> pygm.utils.from_graphml(filename)
array([[0.29440151, 0.66468829, 0.05403941, 0.85887567],
       [0.48120964, 0.01429095, 0.73536659, 0.02962113],
       [0.3815578 , 0.93356234, 0.01332568, 0.61149257],
       [0.15422904, 0.64656912, 0.93219422, 0.784769  ]])