mlx_graphs.utils.convert.to_networkx

Contents

mlx_graphs.utils.convert.to_networkx#

mlx_graphs.utils.convert.to_networkx(data: GraphData, remove_self_loops: bool = False) networkx.DiGraph[source]#

Converts a mlx_graphs.data.GraphData instance to a a directed networkx.DiGraph otherwise.

Parameters:
  • data (GraphData) – Graph data object

  • remove_self_loops (bool) – If set to True, will not include self-loops in the resulting graph. (default: False)

Return type:

DiGraph

Returns:

A networkx graph

Examples:

import mlx.core as mx

edge_index = mx.array(
    [
        [0, 1, 1, 2, 2, 3],
        [1, 0, 2, 1, 3, 2],
    ]
)
node_features = mx.array([[1], [1], [1], [1]])
data = GraphData(node_features=node_features, edge_index=edge_index)
G = to_networkx(data)
print(G.edges)
>>> OutEdgeView([(0, 0), (0, 1), (1, 0), (1, 2), (2, 1), (2, 3), (3, 2)])