mlchem.chem.calculator.tools.calc_centroid

calc_centroid(coordinates: ndarray, masses: Iterable | None = None) ndarray

Calculate the centroid of a set of points, optionally weighted by masses.

Parameters:
  • coordinates (np.ndarray) – A 2D array of shape (N, D) where N is the number of points.

  • masses (Iterable, optional) – An iterable of length N representing the masses of each point.

Returns:

The coordinates of the centroid.

Return type:

np.ndarray

Examples

>>> calc_centroid(np.array([[0, 0], [2, 0], [1, 2]]))