Any clustering algorithms for points which are equidistant apart, holding different values?

Viewed 31

I have a data set with equidistant points with different values, like a 2D matrix, for example:

[[1, 2, 1, 5, 6]
 [2, 1, 4, 7, 6],
 [5, 1, 9, 3, 7]]

I want to do clustering based on the value, but with the points being spatially (equidistant) constrained. I plot this data in a colourmap, so perhaps to group the data based on values close to each other.

Are there any algorithms for this?

(Edited for clarity)

1 Answers

Maybe you should try skimage.slic or a similar algorithm from the example in skimage.segmentation

import numpy as np
from skimage import segmentation

a = np.array([[1, 2, 1, 5, 6],
 [2, 1, 4, 7, 6],
 [5, 1, 9, 3, 7]])

segments = segmentation.slic(a, n_segments=4)

print(segments)

>>> [[0 0 1 1 2]
     [0 0 1 1 2]
     [3 3 4 4 5]]

You can then adjust the compactness and number of segments to your need

Related