to_networkx
¶
to_networkx(data: GraphData, remove_self_loops: bool = False) -> DiGraph
Converts a mlx_graphs.data.GraphData instance to a
a directed networkx.DiGraph otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
Graph data object |
required |
remove_self_loops
|
bool
|
If set to |
False
|
Returns:
| Type | Description |
|---|---|
DiGraph
|
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)])
Source code in mlx_graphs/utils/convert.py
from mlx_graphs.utils.convert import to_networkx · mlx_graphs/utils/convert.py