After applying clustering algorithm I need to extract those data which exists centre of the cluster and which exists border of the cluster. How could I do this by using python.

I use k-means clustering algorithm and divide those data into 19 cluster. I am also using scikit learn library.


Here's my plot after clustering: enter image description here

  • $\begingroup$ Can you share a plot of your data?We might need to manually trim the data(not quite sure) as we will have different centroids coordinates.. $\endgroup$
    – Aditya
    Commented Feb 25, 2018 at 17:36
  • $\begingroup$ As I am new in clustering and I have 682 instances with 35 features that's why I don't know how I can plot? If I provides centroids willbe it helpful ? $\endgroup$
    – IS2057
    Commented Feb 25, 2018 at 17:44

1 Answer 1


You can use numpy.where documentation can be fouind here : https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html

You can define a function to extract your data ID somthing like this

def ClusterIndicesNumpy(clustNum, labels_array): 
    return np.where(labels == cluster)[0]

To get samples from cluster 3 for example:

ClusterIndicesNumpy(3, km.labels_)
  • $\begingroup$ I need those data in every(19) cluster that are very close to the centre. By using numpy.where how could I identify those data ? $\endgroup$
    – IS2057
    Commented Feb 26, 2018 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.