Problem Setup:
points- 2Dnumpy.arrayof lengthN.centroids- 2Dnumpy.arraythat I get as an output fromK-Meansalgorithm, of lengthk<N.- as a centroid initialization routine for an
MLEalgorithm, I want to assign each point inpointsa random centroid fromcentroids.
Required Output:
- A
numpy.arrayof shape (N, 2), of randomly chosen 2D points fromcentroids
My Efforts:
- I've tried using the
numpy.takewith thenumpy.random.choiceas shown inCode 1, but it doesn't return the desired output.
Code 1:
import numpy as np
a = np.random.randint(1, 10, 10).reshape((5, 2))
idx = np.random.choice(5, 20)
np.take(a, idx)
Out: array([6, 2, 3, 3, 8, 2, 5, 2, 6, 3, 3, 8, 6, 6, 6, 6, 8, 2, 6, 5])
From numpy.take documentation page I've learned that it chooses items from flattened array, which is not what I need.
I'd appreciate any ideas on how to accomplish this task. Thanks in advance for any help.