mesa.multiomics.multiomics_spatial.get_spatial_knn_indices

mesa.multiomics.multiomics_spatial.get_spatial_knn_indices(locations, n_neighbors=15, method='kd_tree')

Compute the k-nearest neighbors (k-NN) of each location in a given data matrix.

Parameters:
  • locations (numpy.ndarray of shape (n_samples, 2)) – The data matrix representing locations where each row corresponds to a point in 2D space.

  • n_neighbors (int, optional) – The number of nearest neighbors to identify for each location. Default is 15.

  • method (str, optional) – The method used to compute the nearest neighbors. Options include ‘ball_tree’, ‘kd_tree’, and ‘brute’. Default is ‘kd_tree’.

Returns:

An array where each row represents the indices of the nearest neighbors for that sample, ordered by proximity.

Return type:

numpy.ndarray of shape (n_samples, n_neighbors)