nearest
¶
nearest(
x: array,
y: array,
batch_x: Optional[array] = None,
batch_y: Optional[array] = None,
) -> array
Assigns each point of x to its nearest point of y, in the same
graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
Points to assign, of shape |
required |
y
|
array
|
Cluster centers, of shape |
required |
batch_x
|
Optional[array]
|
Graph of each point of |
None
|
batch_y
|
Optional[array]
|
Graph of each point of |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The index in |
array
|
shape |
Example:
import mlx.core as mx
from mlx_graphs.utils import nearest
x = mx.array([[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0]])
y = mx.array([[-1.0, 0.0], [1.0, 0.0]])
>>> nearest(x, y)
array([0, 0, 1, 1], dtype=int32)
Source code in mlx_graphs/utils/clustering.py
from mlx_graphs.nn import nearest · mlx_graphs/utils/clustering.py