So lets say i have a numpy array that holds points in 2d space, like the following
np.array([[3, 2], [4, 4], [5, 4], [4, 2], [4, 6], [9, 5]])
I also have a numpy array that labels each point to a number, this array is a 1d array with the length as the number of points in the point array.
np.array([0, 1, 1, 0, 2, 1])
Now i want to take the mean value of each point that have an index from the labels array. So for all points that have label 0, take the mean value of those points. My current way of solving this is the following way
return np.array([points[labels==k].mean(axis=0) for k in range(k)])
where k is the largest number in the labels array, or as it's called the number of ways to label the points.
I would like a way to do this without using a for loop, maybe some numpy functionality i haven't discovered yet?