Skip to content

Instantly share code, notes, and snippets.

View l4rz's full-sized avatar

Mike K. l4rz

View GitHub Profile
@crowsonkb
crowsonkb / spherical_avg.py
Created April 26, 2021 22:51
Spherical weighted average
import geoopt
def spherical_avg(p, w=None, tol=1e-6):
sphere = geoopt.Sphere()
if w is None:
w = p.new_ones([p.shape[0]])
assert p.ndim == 2 and w.ndim == 1 and len(p) == len(w)
w = w / w.sum()
p = sphere.projx(p)