import torch


def pts_center(pts, weights):
  """Estimate the center of mass of a scene."""
  total_weight = torch.sum(weights)
  origin_weights = weights[Ellipsis, None] / total_weight
  origin = origin_weights * pts
  reduce_dims = tuple(range(origin.ndim - 1))
  origin = origin.sum(dim=reduce_dims)  # Sum except last dim.
  return origin, total_weight