1
$\begingroup$

In scikit-learn, or other python libraries, are there any existing implementations to compute centroid for high dimensional data sets?

$\endgroup$
1
  • $\begingroup$ In case the number of instances is very high, a simple solution is to take a random subset. $\endgroup$
    – Erwan
    Apr 23, 2022 at 11:50

1 Answer 1

1
$\begingroup$

You could try using np.mean along the axis that you care about. Let's say you have 100 vectors of 1200 dimensions each, and you want a centroid vector of dimension 1200. Then the following code would work:

>>> import numpy as np
>>> data = np.random.rand(100, 1200)
>>> centroid = np.mean(data, axis=0)
>>> centroid.shape
(1200,)

Here's documentation for the function.

$\endgroup$

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.