code to match data point to closest centroid and group them by index of data point