mlx_graphs.utils.convert.from_networkx

Contents

mlx_graphs.utils.convert.from_networkx#

mlx_graphs.utils.convert.from_networkx(data: networkx.Graph) GraphData[source]#

Converts a networkx.Graph or networkx.DiGraph to a mlx_graphs.data.GraphData instance.

Parameters:

data (Graph) – A networkx graph

Return type:

GraphData

Returns:

A GraphData object

Examples:

import networkx as nx
from mlx_graphs.utils.convert import from_networkx

G = nx.Graph()
G.add_node(1)
G.add_node(2)
G.add_node(3)
G.add_node(4)
G.add_edge(1, 2)
G.add_edge(1, 3)
G.add_edge(2, 3)
G.add_edge(3, 4)
mlx_dataset = from_networkx(G)
print(mlx_dataset)
>>> GraphData(edge_index(shape=(2, 4), int32))
print(mlx_dataset.num_nodes)
>>> 4