mlx_graphs.utils.transformations.to_sparse_adjacency_matrix#
- mlx_graphs.utils.transformations.to_sparse_adjacency_matrix(adjacency_matrix: mlx.core.array, *, dtype: mlx.core.Dtype = mlx.core.uint32) tuple[mlx.core.array, mlx.core.array] [source]#
Converts an adjacency matrix to a sparse representation as a tuple of edge index and edge features.
- Parameters:
- Return type:
- Returns:
A tuple representing the edge index and edge features
Example:
matrix = mx.array( [ [0, 1, 2], [3, 0, 0], [5, 1, 2], ] ) edge_index, edge_features = to_sparse_adjacency_matrix(matrix) edge_index # mx.array([[0, 0, 1, 2, 2, 2], [1, 2, 0, 0, 1, 2]]) edge_features # mx.array([1, 2, 3, 5, 1, 2])