Skip to content

Instantly share code, notes, and snippets.

@Bktero
Last active July 27, 2017 07:47
Show Gist options
  • Save Bktero/5ac05da9288c67c76f92fd7f6e2dbed9 to your computer and use it in GitHub Desktop.
Save Bktero/5ac05da9288c67c76f92fd7f6e2dbed9 to your computer and use it in GitHub Desktop.
[Python] Compute barycenter
import functools
import operator
points = [100, 66, 33, 0]
weights = [-50, 0, 0, 0]
numerator = functools.reduce(operator.add, [p * w for p, w in zip(points, weights)], 0)
denomimator = functools.reduce(operator.add, weights, 0)
barycenter = numerator / denomimator
print(numerator)
print(denomimator)
print(barycenter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment