to_scipy_sparse_matrix
¶
to_scipy_sparse_matrix(
edge_index: array,
edge_features: Optional[array] = None,
num_nodes: Optional[int] = None,
) -> Any
Converts a graph given by edge_index (and optional scalar edge
features) to a scipy.sparse.coo_matrix. Requires scipy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge |
required |
edge_features
|
Optional[array]
|
Optional scalar weight of each edge, of shape
|
None
|
num_nodes
|
Optional[int]
|
Number of nodes in the graph. Inferred from |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A |
Example:
edge_index = mx.array([[0, 1, 1], [1, 0, 2]])
to_scipy_sparse_matrix(edge_index).toarray()
# array([[0., 1., 0.],
# [1., 0., 1.],
# [0., 0., 0.]], dtype=float32)
Source code in mlx_graphs/utils/sparse.py
from mlx_graphs.utils import to_scipy_sparse_matrix · mlx_graphs/utils/sparse.py