graphicle.matrix.knn_adj(matrix: ndarray[Any, dtype[float64]], k: int, self_loop: bool = False, weighted: bool = False, row: bool = True, dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | collections.abc.Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any] = None) ndarray[Any, dtype[float64]][source]

Produce a directed adjacency matrix with outward edges towards the k nearest neighbours, determined from the input affinity matrix.

New in version 0.1.0.

Parameters:
matrix : ndarray[float64]

2D matrix of Particle affinities.

k : int

Number of nearest neighbours in result.

weighted : bool

If True edges weighted by affinity, if False edge is binary. Default is False.

self_loop : bool

If False will remove self-edges. Default is False.

row : bool

If True outward edges given by rows, if False cols. Default is True.

dtype : dtype-like, optional

Type of output. Must be floating point if weighted is True.

Returns:

adj – Adjacency matrix representing particle connectivity.

Return type:

ndarray[bool_] or ndarray[float64]

Notes

If weighted is False, the returned adjacency matrix will be boolean.


Last update: Jun 27, 2025